题目链接:http://codeforces.com/contest/682/problem/A
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.
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).
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.
6 12
14
11 14
31
1 5
1
3 8
5
5 7
7
21 21
88
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.
题意
给你一个n和m,让用1到n中的一个数去加上1到m中的一个数,能够实现(x+y)对5求余等于0,这样的数有几组。
代码
//根据题意可知当n=a时,m可选择的方案有(m+a)/5-a/5种,for循环求出1到n的种数和。 #include <iostream> using namespace std; int main() { int n,m,a; __int64 count=0; cin>>n>>m; for(a=1;n>=a;a++){ count+=(m+a)/5-a/5; } cout<<count<<endl; return 0; }