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;
    }
    
  • 相关阅读:
    QListView和QListWidget的区别
    Qt下QTableWidget的使用
    用c++封装linux系统调用
    读写锁的简单示例
    SQL 使用序列
    SQL 事务
    SQL ALTER TABLE 命令
    SQL 语句快速参考
    java中三种常见内存溢出错误的处理方法(good)
    Java 内存溢出(java.lang.OutOfMemoryError)的常见情况和处理方式总结
  • 原文地址:https://www.cnblogs.com/Sunshine-tcf/p/5690183.html
Copyright © 2011-2022 走看看