题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803

Knowledge Point:

  同余定理:两个整数a、b,若它们除以整数m所得的余数相等,则称a与b对模m同余或a同余于b模m。记作 a≡b(mod m)

    加法运用: (a + b) % m = (a % m + b % m) % m

    乘法运用: (a * b) % m = ((a % m) * (b % m)) % m

     高精度取模: 一个高精度数对一个数取余,可以把高精度数看成各位数的权值与个位数乘积的和。

          eg: 1234  = ((1*10+2) *10+3) *10+4, 综合运用上面的加法和乘法运用公式求解;

 string a = "1234";
int ans = ;
for(int i = ; i < a.length; i++){
ans = (ans * + a[i] - '') % mod;
}
cout << ans << endl;

     快速幂取模:  将幂拆解为多个底数的平方次的积,如果指数为偶数,把指数除以2,并让底数的平方次取余,如果指数为奇数,就把多出来的底数记录下来,再执行偶数次的操作。

 int PowerMod(int a, int b, int mod){
int ans = ; //a-底数,b-质数
a = a % mod;
while(b > ){
if(b&){
ans *= (a % mod);
}
b >>= ;
a = (a * a) % mod;
}
ans %= mod;
return ans;
}

Summarize:

  1. 同余定理运用;

  2. 数据范围爆 int,使用 long long;

  3. 如果 (i*j)%mod==0 则有 (i*j+mod)%mod==0 ;

  一开始我选择求2016的所有因数,循环将 n 和 m 中因数的倍数个数相乘再将所有结果相加。但可能出现某一个数 x 同时是多个因数的公倍数,且

2016/x 恰好也是多个因数的公倍数,出现重复,故该方法不能通过。

附代码:

 /*
题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 2016
给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:
1. 1≤a≤n,1≤b≤m;
2. a×b 是 2016 的倍数。
输入每组数据包含两个整数 n,m (1≤n,m≤10e9). Sample Input
32 63
2016 2016
1000000000 1000000000 Sample Output
1
30576
7523146895502644
*/
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
using namespace std; #define LL long long
const int N = ;
LL n,m,ans;
LL a[N], b[N]; int main()
{
ios::sync_with_stdio(false); while(cin>>n>>m)
{
ans=;
for(int i=; i<N; i++)
{ a[i]=n/N; b[i]=m/N;}
for(int i=; i<=n%N; i++) a[i]++;
for(int i=; i<=m%N; i++) b[i]++; for(int i=; i<N; i++)
for(int j=; j<N; j++)
if(i*j%N == )
ans += a[i]*b[j];
cout<<ans<<endl;
} return ;
}

十二届 - CSU 1803 :2016(同余定理)的更多相关文章

  1. CSU 1803 - 2016 - [同余]

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. ...

  2. CSU 1803 2016(数论)

    2016 Problem Description: 给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1≤a≤n,1≤b≤m; a×b 是 2016 的倍数. Input: 输 ...

  3. CSU 1803 2016 湖南省2016省赛

    1803: 2016 Submit Page   Summary   Time Limit: 5 Sec     Memory Limit: 128 Mb     Submitted: 1416    ...

  4. CSU 1803 2016

    湖南省第十二届大学生计算机程序设计竞赛$A$题 枚举. 处理一下$\% 2016$之后的数分别有几个,然后$2016*2016$枚举一下统计方案数就可以了. #pragma comment(linke ...

  5. 【模拟】【数学】CSU 1803 2016 (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1803 题目大意: 给定n,m(n,m<=109)1<=i<=n,1& ...

  6. CSU - 1803 —— 数学题

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Description  给出正整数 n 和 m,统计满足以下条件的正整数对 ...

  7. 2016年湖南省第十二届大学生计算机程序设计竞赛---Parenthesis(线段树求区间最值)

    原题链接 http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1809 Description Bobo has a balanced parenthes ...

  8. 2016湖南省赛----A 2016 (同余定理)

    2016湖南省赛----A 2016 (同余定理) Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量: 1. 1≤a≤n,1≤b≤m; 2. a×b 是 ...

  9. 湖南省第十二届大学生计算机程序设计竞赛 A 2016

    1803: 2016 Description  给出正整数 n 和 m,统计满足以下条件的正整数对 (a,b) 的数量:   1. 1≤a≤n,1≤b≤m; 2. a×b 是 2016 的倍数. In ...

随机推荐

  1. YTU 2508: 武功秘籍

    2508: 武功秘籍 时间限制: 1 Sec  内存限制: 128 MB 提交: 1384  解决: 438 题目描述 小明到X山洞探险,捡到一本有破损的武功秘籍(2000多页!当然是伪造的).  他 ...

  2. ubuntu14安装docker-ce

    先卸载旧的docker sudo apt-get remove docker docker-engine docker.io docker-ce 通过HTTPS使用存储库(repository) su ...

  3. Python Tricks(十九)—— switch 的实现

    python 原生语法不支持 switch,体现了 Python 大道至简的设计思路,有时为了避免啰嗦的 if elif等判断语句,我们可以用字典来代替 switch 的各分支,也即建立表达式和操作的 ...

  4. 近年来火热的人工智能,其实是IT业界的一个障眼法

    近年来火热的人工智能,其实是IT业界的一个障眼法,仗着现在的计算机的计算能力牛B,把一个类仿生统计算法,宣传成了人工智能,不得不感叹一些营销人士的牛逼,说大话不腰疼.当然谎言重复一千遍也许自己也就信了 ...

  5. bzoj1076: [SCOI2008]奖励关(期望dp+状压dp)

    1076: [SCOI2008]奖励关 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2989  Solved: 1557[Submit][Statu ...

  6. 第八届河南省省赛 A.挑战密室

    挑战密室 时间限制: ms | 内存限制: KB 难度: 描述 R组织的特工Dr. Kong 为了寻找丢失的超体元素,不幸陷入WTO密室.Dr. Kong必须尽快找到解锁密码逃离,否则几分钟之后,WT ...

  7. SQL 索引篇

    索引介绍: 1.索引是对数据库表中一列或多列的值进行排序的一种结构,使用索引可快速访问数据库表中的特定信息. 数据库索引好比是一本书前面的目录, SQL Server的B树结构 2.加快数据库的查询速 ...

  8. 类似QQ消息左滑删除的Demo

    最近在网上学到一篇类似QQ消息左滑删除的demo,完善了下代码,感觉还不错,特此分享一波: CustomSwipeListView.java 是个继承自ListView的类,里面调用了自定义View ...

  9. Android 性能优化(14)网络优化( 10)Determining and Monitoring the Connectivity Status

    Determining and Monitoring the Connectivity Status This lesson teaches you to Determine if you Have ...

  10. 387 First Unique Character in a String 字符串中的第一个唯一字符

    给定一个字符串,找到它的第一个不重复的字符,并返回它的索引.如果不存在,则返回 -1.案例:s = "leetcode"返回 0.s = "loveleetcode&qu ...