CSU 1803 2016(数论)

2016

Problem Description:

给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:

  1. 1≤a≤n,1≤b≤m;
  2. a×b 是 2016 的倍数。

Input:

输入包含不超过 30 组数据。
每组数据包含两个整数 n,m (1≤n,m≤109).

Output:

对于每组数据,输出一个整数表示满足条件的数量。

Sample Input:

32 63
2016 2016
1000000000 1000000000

Sample Output:

1
30576
7523146895502644
这题赛后发现还是可以做出来的,但比赛时看了近1小时都没思路,果然比赛时平常心很重要。

【题目链接】CSU 1803 2016

【题目类型】模运算

&题解:

可以求出在[1,N]中,模为[1,2016]的数的个数; 以及在[1,M]中,模为[1,2016]的数的个数。分别存进a b数组,
因为x ∗y%2016=x%2016 ∗y%2016,接下来判断(x%2016 ∗y%2016)%2016是否为0,如果是那么他们的情况就有a[i]*b[j]种(注意:这块一定要用ll,因为这块最大的话都是1e6,乘起来就是1e12,会爆int),最后相加,输出就好。
【时间复杂度】O(2016^2)

&代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
#define cle(a,val) memset(a,(val),sizeof(a))
#define SII(N,M) scanf("%d %d",&(N),&(M))
#define rez(i,a,b) for(int i=(a);i<=(b);i++)
#define PI(A) cout<<(A)<<endl;
const int MAXN = 2016 + 5 ;
int a[MAXN],b[MAXN];
int n,m;
void Solve()
{
    while(~SII(n,m))
    {
        cle(a,0),cle(b,0);
        rez(i,1,2016) a[i]=n/2016;
        rez(i,1,2016) b[i]=m/2016;
        rez(i,1,n%2016) a[i]++;
        rez(i,1,m%2016) b[i]++;
        ll ans=0;
        rez(i,1,2016)
        rez(j,1,2016)
        {
            if (i*j%2016==0)
                ans+=(ll)a[i]*b[j];
        }
        PI(ans)
    }
}
int main()
{
    Solve();
    return 0;
}

转载于:https://www.cnblogs.com/s1124yy/p/5845322.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值