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

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<bits/stdc++.h>
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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值