[CSU 1803 2016]数学

[CSU 1803 2016]数学

题目链接[CSU 1803 2016]
题意描述:略。
解题思路:可以求出在 [1,N] 中,模为 [0,2016] 的数的个数; 以及在 [1,M] 中,模为 [0,2016] 的数的个数。复杂度 O(2016)
因为 xy%2016=x%2016y%2016 ,那么,接下来就只需要统计求和就OK了。
这个题目的容斥,我一直还没有搞清…

#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

//#pragma comment(linker, "/STACK:1024000000,1024000000")

#define FIN             freopen("input.txt","r",stdin)
#define FOUT            freopen("output.txt","w",stdout)
#define fst             first
#define snd             second

typedef long long LL;
typedef pair<int, int> PII;

const int MAXN = 2016 + 5;
const int INF  = 0x3f3f3f3f;

LL N, M;
LL cnta[MAXN], cntb[MAXN];

int main() {
#ifndef ONLINE_JUDGE
    FIN;
#endif // ONLINE_JUDGE
    LL x, y, ans;
    while(~scanf("%lld %lld", &N, &M)) {
        memset(cnta, 0, sizeof(cnta));
        memset(cntb, 0, sizeof(cntb));
        x = N / 2016, y = N % 2016;
        for (LL i = 0; i < 2016; i++) {
            if(i != 0 && i <= y) cnta[i] = x + 1;
            else cnta[i] = x;
        }
        x = M / 2016, y = M % 2016;
        for (LL i = 0; i < 2016; i++) {
            if(i != 0 && i <= y) cntb[i] = x + 1;
            else cntb[i] = x;
        }
        ans = 0;
        for (LL i = 0; i < 2016; i++) {
            if(cnta[i] == 0) continue;
            for (LL j = 0; j < 2016; j++) {
                if(cntb[j] == 0) continue;
                if(i * j % 2016 == 0) {
                    ans += cnta[i] * cntb[j];
                }
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值