12th湖南省赛 A-2016(同余定理)
来源:互联网 发布:美工学徒 编辑:程序博客网 时间:2024/05/19 17:26
//例行周赛,结果报零了,QaQ
题目如下:
给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:
1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数。
Input
输入包含不超过 30 组数据。每组数据包含两个整数 n,m (1≤n,m≤10 9).
Output
对于每组数据,输出一个整数表示满足条件的数量。
Sample Input
32 632016 20161000000000 1000000000
Sample Output
1305767523146895502644
思路:
由同余定理得 (a*b)%c=(a%c * b%c)%c
这样,我们就可以将数据范围控制在2016以内
对于数p在[1, n]内,统计p mod 2016==i 的个数;在[1,m]区间类似。
代码如下:
#include <algorithm>#include <bitset>#include <cassert>#include <climits>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <deque>#include <iomanip>#include <iostream>#include <map>#include <numeric>#include <queue>#include <set>#include <stack>#include <string>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;void get_ab(ll p, ll c[]){ ll temp=p/2016; ll cnt=p%2016; c[0]=temp; for(ll i=1;i<=cnt;i++)//在n%2016范围内的数需要加一 c[i]=temp+1; for(ll i=cnt+1;i<2016;i++) c[i]=temp;}int main(){ ll a[2016],b[2016]; ll n,m; while(scanf("%lld%lld",&n,&m)!=EOF){ get_ab(n,a); get_ab(m,b); ll ans=0; for(int i=0;i<2016;i++){//缩小范围到2016*2016 for(int j=0;j<2016;j++){ if((i*j)%2016==0)ans+=a[i]*b[j]; } } printf("%lld\n",ans); } return 0;}
参考题解:
http://blog.csdn.net/qq_33184171/article/details/70835664
0 0
- 12th湖南省赛 A-2016(同余定理)
- CSU 1803 2016(16湖南省赛)(同余定理)
- CSU Problem 1803 2016(同余定理)——湖南省第十二届大学生计算机程序设计竞赛
- 2016 (同余定理)
- ZOJ-3609-Modular Inverse【同余定理】【9th浙江省赛】
- CSU-1803: 2016 ,同余定理!
- 同余定理
- 同余定理
- 同余定理
- 同余定理
- 同余定理
- 同余定理
- 大数同余定理
- 同余定理
- 同余定理
- 同余定理
- 同余定理
- 同余定理
- (译)神经网络基础(1):Logistic 回归
- 网络编程—TCP三次握手四次挥手的理解
- java对象转js对象
- 本地nodejs服务(笔记)
- 查找算法的时间复杂度
- 12th湖南省赛 A-2016(同余定理)
- NDk的初使用
- Html中typeof的用法
- improve your python code(8)
- SpringMVC运行流程图
- python实现pcd转txt
- 给IT大学生的10个忠告
- GDOI2017总结
- Android 腾讯X5浏览器 初始化不成功的原因