随笔分类 -  ACM_数论

摘要://http://acm.hdu.edu.cn/showproblem.php?pid=1098/*题目说x任意,于是取x=1,公式变为f(x)=5+13+k*a然后从小到大枚举a,满足f(x)%65==0即输出,枚举a为1到64,因为a>=65时可简化为 65+i,65可以约去有一个函数: f(x)=5*x^13+13*x^5+k*a*x给定一个非负的 k 值 求最小的非负的 a 值 使得对任意的整数x都能使 f(x) 被 65 整除。每输入一个k 值 , 对应输出一个 a值 , 若不存在a值 则输出 no 数学归纳法证明:1.假设当x=n时,f(n)=........... 阅读全文
posted @ 2013-10-22 20:27 Geekers 阅读(483) 评论(0) 推荐(0)
摘要://http://acm.hdu.edu.cn/showproblem.php?pid=2098//标准的筛选法 #includeusing namespace std;bool prime[10000+5]; //题目中给出了数值不会超过10000,这样刚好能够用筛选法 void Init() //直接初始化素数表就好了。 { for(int i = 2; i <= 10000; ++i) //初始条件为都是素数 { prime[i] = true; } for(int i =2;i <= 10000; ++i) ... 阅读全文
posted @ 2013-10-17 22:00 Geekers 阅读(283) 评论(0) 推荐(0)
摘要://超级水题,热身的,没必要解释//http://acm.hdu.edu.cn/showproblem.php?pid=2161#includeusing namespace std;bool IsPrime(int n){ int i = 0; if(n0 ) { count++; if(IsPrime(N)) printf("%d: yes\n",count); else printf("%d: no\n",count); } return 0;} 阅读全文
posted @ 2013-10-17 21:38 Geekers 阅读(220) 评论(0) 推荐(0)
摘要://http://acm.hdu.edu.cn/showproblem.php?pid=1395//同样,快速幂取余不用解释,注意点输出格式就行了//注意全部使用位运算#includeusing namespace std;__int64 Montgomery(int a, int b, int r){ __int64 ans=1, buff=a; while(b) { if(b&1) ans = ans*buff%r; buff = buff*buff%r; b>>=1; } return ans;}int ma... 阅读全文
posted @ 2013-10-17 20:30 Geekers 阅读(250) 评论(0) 推荐(0)
摘要:人见人爱A^BTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 17481Accepted Submission(s): 12376Problem Description求A^B的最后三位数表示的整数。说明:A^B的含义是“A的B次方”Input输入数据包含多个测试实例,每个实例占一行,由两个正整数A和B组成(1 3 4 using namespace std; 5 6 __int64 qpow(int a,int b,int r) 7 {... 阅读全文
posted @ 2013-10-17 20:16 Geekers 阅读(298) 评论(0) 推荐(0)
摘要:本文地址:http://www.cnblogs.com/Lee-geeker/p/3372084.html转载请注明。1.最大公约数和最小公倍数。//模版int gcd(int a, int b){ if(ausing namespace std;int gcd(int a, int b){ if(a>=1; } return ans;}可参考题目:HDU1395 http://acm.hdu.edu.cn/showproblem.php?pid=1395#includeusing namespace std;unsigned Montgomery(unsigned ... 阅读全文
posted @ 2013-10-16 13:41 Geekers 阅读(1473) 评论(0) 推荐(0)
摘要:交了4次才过,以为很简单,结果大意了。。注意两个问题:一个是考虑可能的溢出情况,这个以前就遇到过,所以这里没有忘记 1 int lcm(int a, int b) 2 { 3 return a/gcd(a,b)*b; 4 } 5 6 7 //避免写成这样 8 int lcm(int a, int b) 9 {10 return a*b/gcd(a,b); //可能会溢出11 }第二个是考虑特殊数据1 //如果数据是这个样子的2 23 1 34 1 45 6 这样只有一个数据7 那么直接输入a[0],即为最大公约数了考虑以上就能轻松AC 1 #include 2 3 usi... 阅读全文
posted @ 2013-10-09 14:25 Geekers 阅读(320) 评论(0) 推荐(0)
摘要:Eddy's digital RootsTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3561 Accepted Submission(s): 2013Problem DescriptionThe digital root of a positive integer is found by summing the digits of the integer. If the resulting value is a sin... 阅读全文
posted @ 2013-08-14 15:57 Geekers 阅读(346) 评论(0) 推荐(0)
摘要:How many prime numbersProblem DescriptionGive you a lot of positive integers, just to find out how many prime numbers there are.InputThere are a lot of cases. In each case, there is an integer N representing the number of integers to find. Each integer won’t exceed 32-bit signed integer, and each of 阅读全文
posted @ 2013-08-06 19:23 Geekers 阅读(333) 评论(0) 推荐(0)