zoukankan      html  css  js  c++  java
  • CodeForces 682A Alyona and Numbers (水题)

    Alyona and Numbers

    题目链接:

    http://acm.hust.edu.cn/vjudge/contest/121333#problem/A

    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 ≤ 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.

    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

    题意:

    找出有多少数对(x, y), 1 ≤ x ≤ n, 1 ≤ y ≤ m 使得x+y能整除5;

    题解:

    直接模拟找出所有数模5的同余数;
    注意long long;

    代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <map>
    #include <set>
    #include <vector>
    #define LL long long
    #define eps 1e-8
    #define maxn 110
    #define inf 0x3f3f3f3f
    #define IN freopen("in.txt","r",stdin);
    using namespace std;
    
    int n,m;
    LL a[6],b[6];
    
    int main(int argc, char const *argv[])
    {
        //IN;
    
        while(scanf("%d %d",&n,&m) != EOF) {
            memset(a, 0, sizeof(a));
            memset(b, 0, sizeof(b));
    
            for(int i=1; i<=n; i++){
                a[i%5]++;
            }
            for(int i=1; i<=m; i++){
                b[i%5]++;
            }
    
            LL ans = a[0] * b[0];
            for(int i=1; i<5; i++) {
                ans += a[i]*b[5-i];
            }
    
            printf("%I64d
    ", ans);
        }
    
        return 0;
    }
    
  • 相关阅读:
    Java中Io类-File类的构造方法
    hadoop的wordcount例子运行
    关于“javax.servlet.include.request_uri”属性值
    如何高效地分析框架源码
    代码重构的技巧——合理使用@Deprecated
    spring的事件机制
    在eclipse中使用jetty插件替代m2e开发调试maven web项目
    maven多配目配置总结
    如何禁止anonymous用户访问nexus
    efront二次开发记要
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5690183.html
Copyright © 2011-2022 走看看