CodeForces 682A

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121183#problem/A

A - Alyona and Numbers
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  CodeForces 682A

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<=x<=n,1<=y<=m,(x+y)%==0)有序对(x,y)的个数

暴力超时;

找到其中的规律很重要

#include
using namespace std;
typedef long long ll;
int main()
{
    int n,m;
    while(~scanf("%d%d",&n,&m)){
        ll sum=0;
        for(int i=1;i<=n;++i){
            int j=1;
            for(;;++j)
                if((i+j)%5==0)break;
            int s=j;
            for(j=m;;--j)
                if((i+j)%5==0)break;
            int e=j;
            if(s<=e)
                sum+=((e-s)/5+1);
        }
        printf("%I64d\n",sum);
    }
    return 0;
}


你可能感兴趣的:(CodeForces 682A)