Codeforces Round #358 (Div. 2) A Alyona and Numbers(水题)
2016-07-02 14:26
483 查看
思路:(x+y)%5==0,余数的组合可以有(0,0),(1,4),(2,3),(3,2),(4,1)五种,那么分别计算出来就可以了、
#include<bits\stdc++.h>
using namespace std;
#define LL long long
LL num1[6];
LL num2[6];
int main()
{
LL n,m;
cin >> n >> m;
for(int i = 0;i<5;i++)
{
num1[i]=n/5;
if(n%5>=i)
num1[i]++;
num2[i]=m/5;
if(m%5>=i)
num2[i]++;
}
num1[0]--;
num2[0]--;
LL ans = 0;
ans+=num1[0]*num2[0]+num1[1]*num2[4]+num1[2]*num2[3]+num1[3]*num2[2]+num1[4]*num2[1];
cout << ans << endl;
}
A. Alyona and Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
After finishing eating her bun, Alyona came up with two integers n and m.
She decided to write down two columns of integers — the first column containing integers from 1 to n and
the second containing integers from 1 to m.
Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and
equals 0.
As usual, Alyona has some troubles and asks you to help.
Input
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).
Output
Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is
divisible by 5.
Examples
input
output
input
output
input
output
input
output
input
output
input
output
Note
Following pairs are suitable in the first sample case:
for x = 1 fits y equal
to 4 or 9;
for x = 2 fits y equal
to 3 or 8;
for x = 3 fits y equal
to 2, 7 or 12;
for x = 4 fits y equal
to 1, 6 or 11;
for x = 5 fits y equal
to 5 or 10;
for x = 6 fits y equal
to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case.
#include<bits\stdc++.h>
using namespace std;
#define LL long long
LL num1[6];
LL num2[6];
int main()
{
LL n,m;
cin >> n >> m;
for(int i = 0;i<5;i++)
{
num1[i]=n/5;
if(n%5>=i)
num1[i]++;
num2[i]=m/5;
if(m%5>=i)
num2[i]++;
}
num1[0]--;
num2[0]--;
LL ans = 0;
ans+=num1[0]*num2[0]+num1[1]*num2[4]+num1[2]*num2[3]+num1[3]*num2[2]+num1[4]*num2[1];
cout << ans << endl;
}
A. Alyona and Numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
After finishing eating her bun, Alyona came up with two integers n and m.
She decided to write down two columns of integers — the first column containing integers from 1 to n and
the second containing integers from 1 to m.
Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and
equals 0.
As usual, Alyona has some troubles and asks you to help.
Input
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).
Output
Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is
divisible by 5.
Examples
input
6 12
output
14
input
11 14
output
31
input
1 5
output
1
input
3 8
output
5
input
5 7
output
7
input
21 21
output
88
Note
Following pairs are suitable in the first sample case:
for x = 1 fits y equal
to 4 or 9;
for x = 2 fits y equal
to 3 or 8;
for x = 3 fits y equal
to 2, 7 or 12;
for x = 4 fits y equal
to 1, 6 or 11;
for x = 5 fits y equal
to 5 or 10;
for x = 6 fits y equal
to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case.
相关文章推荐
- StackExchange和它的游戏规则
- DAA和CMAC
- http://blog.csdn.net/steveguoshao/article/details/38414145
- Linux内核---2.TQ2440系统移植出现的问题总结
- linux服务器jre和tomcat配置
- redis info 命令查看redis使用情况
- Linux内核---1.TQ2440使用总结
- git之常用指令
- thinkphp3.2和phpexcel导入
- Win7系统不能上网怎么办?Win7系统卸载金山软件后无法上网的解决方法
- 重写ScrollView实现ScrollView可以添加悬浮条
- ios xml库选择
- PHP编写文件多服务器同步程序
- 深入浅出RPC(二)
- HeadFirstJava——4_对象的行为
- (c++)——内联函数
- Beego源码分析(转)
- MBTiles地图瓦片管理工具
- 5-10 韩信点兵 (10分)
- form表单,AJAX上传文件