[CSU 1803(湖南省赛16)] 2016 (数论+模运算)
来源:互联网 发布:钢结构cad软件 编辑:程序博客网 时间:2024/06/09 17:57
CSU - 1803 (湖南省赛16)
给定
N 和M ,问有多少对a 和b
其中1≤a≤N ,1≤b≤M ,且a×b%2016=0
刚开始想错了,导致我花了很多时间去思考如何去重
后来看到一种特别机智的做法
所以只要枚举
对于每个这样的余数,找出有多少个
然后对于
这样统计就方便多了
别忘了最后减去
#pragma comment(linker, "/STACK:102400000,102400000")#include <cstdio>#include <iostream>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include <cctype>#include <map>#include <set>#include <queue>#include <bitset>#include <string>#include <complex>using namespace std;typedef pair<int,int> Pii;typedef long long LL;typedef unsigned long long ULL;typedef double DBL;typedef long double LDBL;#define MST(a,b) memset(a,b,sizeof(a))#define CLR(a) MST(a,0)#define SQR(a) ((a)*(a))#define PCUT puts("\n----------")const int maxn=2016+10;LL gcd(LL a, LL b){return b?gcd(b,a%b):a;}int N,M;LL res[maxn];int main(){ #ifdef LOCAL freopen("in.txt", "r", stdin);// freopen("out.txt", "w", stdout); #endif while(~scanf("%d%d", &N, &M)) { LL ans=0; for(int i=0; i<2016; i++) res[i] = M/(2016/gcd(2016,i)); for(int i=0; i<2016; i++) ans += N/2016*res[i]; N%=2016; for(int i=0; i<=N; i++) ans += res[i]; ans -= res[0]; cout << ans << "\n"; } return 0;}
0 0
- [CSU 1803(湖南省赛16)] 2016 (数论+模运算)
- CSU 1803 2016(16湖南省赛)(同余定理)
- CSU 1803:2016(数论)
- csu 1803 2016 2016湖南省赛 A
- csu 1803 16年湖南省赛
- CSU 1803 2016 (数论+思路)
- [CSU 1803(湖南省赛16)] 有向无环图 (DAG+公式化简)
- CSU 1803 2016(数论)
- 2015湖南省赛 CSU 1781: 阶乘除法 (水)
- CSU 1803 2016 (数学)【2016年湖南省第十二届大学生计算机程序设计竞赛 - A】
- [CSU 1808(湖南省赛16)] 地铁 (拆点建图+多源多汇最短路)
- [CSU - 1811 (湖南省赛16)] Tree Intersection (启发式合并)
- csu 1809 Parenthesis 2016湖南省赛 G
- csu 1756 prime(数论)
- [CSU - 1811 (湖南省赛16)] Tree Intersection (dfs序维护子树+离线询问+树状数组)
- csu 1811 Tree Intersection 2016湖南省赛 I
- csu 1503 点到圆弧的距离(第十届湖南省省赛A题,几何)
- 2015湖南省赛 CSU 1783 :聊天止于呵呵(模拟)
- Java中Final关键字的使用
- CURL
- Java NIO详解
- node.js中获取当前时间
- JZOJ3053. 【NOIP2012模拟10.25】旅行
- [CSU 1803(湖南省赛16)] 2016 (数论+模运算)
- MVP 模式在Android中的使用
- 变量声明及转化
- Java基础语法
- 史上最牛中学开学演讲:去到悲欣交集的审美人生
- UVALive4015-Cave(树形dp)
- ElasticSearch基本概念介绍(一)
- 教你实现简单的极光推送-Eclipse
- Java--继承与多态,抽象编程,接口与多态,接口回掉接口编程