A - Alyona and Numbers

Description

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 ≤ n1 ≤ 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 ≤ n1 ≤ y ≤ m and (x + y) is divisible by 5.

 

Sample Input

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

 

题意:

输入两个数n,m。从1~n和1~m中各取一个值,使两值相加为5的倍数,求总共有多少种组合。

 

可从1~n依次取一个值i,并和1~m中的值相加使其和成为5的倍数。

如:6,12时有:1+4,1+9,2+3,2+8,3+2,3+7,3+12...由此我们可见,取值为i时可整除的和的数目为(i+m)/5,可当i>=5时,其本身包含的5的倍数就不能计入总数,如i=6时,和为5就不成立,故总数应减掉i/5。

 

附AC代码:

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 
 7 int main(){
 8     long long n,m;//注意要用long long 
 9     while(cin>>n>>m){
10     long long sum=0; 
11         for(int i=1;i<=n;i++){//将n从1到n循环 
12         sum+=(m+i)/5;
13         if(i>=5)
14         sum-=i/5;
15     } 
16     cout<<sum<<endl;//输出 
17     }
18     return 0;
19 }

 

posted @ 2016-07-11 08:58  Kiven#5197  阅读(364)  评论(0编辑  收藏  举报