随笔分类 -  数论基础

摘要:题目链接http://poj.org/problem?id=1061扩展欧几里得+线性同余方程从题意中很容易得到等式x+mt = y+nt(mod L)//t代表时间移动左右得到 (m-n)t = y-x(mod L);所以 得到(m-n)*a - L*b = y-x的扩展欧几里得,求解a,套上模版就OK了。View Code 1 #include <stdio.h> 2 #include <string.h> 3 __int64 x,y; 4 __int64 ext_eucld(__int64 a,__int64 b) 5 { 6 __int64 t,d; 7 if( 阅读全文
posted @ 2012-08-03 21:23 时光旅行的懒猫 阅读(239) 评论(0) 推荐(0)
摘要:题目链接http://poj.org/problem?id=2115拓展欧几里得算法+线性同余方程题目大意是问A经过多少次能到达B, 当A的值大于 2^k时 A = A%2^k;从题目中可以得到方程: a + c*x = b (mod 2^k) 变形得 c*x = (b-a) (mod 2^k); 再变形得: c*x – 2^k*y = (b – a)解扩展欧几里德方程就可以了View Code 1 #include<iostream> 2 #include<stdio.h> 3 using namespace std; 4 __int64 ext_gct(__int6 阅读全文
posted @ 2012-08-03 21:14 时光旅行的懒猫 阅读(247) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1905题意:给一个 p 和 一个 a,如果这个p 本身就是一个素数,就输出 no,如果不是素数,那么计算( a ^ p) % p 如果结果等于 a 那么输出 yes 否则输出 no也就是伪素数。View Code 1 #include<stdio.h> 2 #include<math.h> 3 __int64 jud(__int64 n) 4 { 5 __int64 i; 6 for(i=2;i*i<n;i++) 7 if(n%i==0) 8 retu... 阅读全文
posted @ 2012-08-03 20:37 时光旅行的懒猫 阅读(429) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2035快速幂取模板View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 int main() 4 { 5 int a,b,cj,jg,i; 6 while(~scanf("%d %d",&a,&b)) 7 { 8 9 if(a==0&&b==0)10 break;11 if(b==0)12 {13 printf("1\n");14 ... 阅读全文
posted @ 2012-08-03 20:32 时光旅行的懒猫 阅读(262) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2503View Code 1 #include<stdio.h> 2 #include<string.h> 3 __int64 gcd(__int64 a,__int64 b) 4 { 5 return b==0?a:gcd(b,a%b); 6 } 7 int main() 8 { 9 __int64 n,a,b,c,d,t,k,m;10 scanf("%I64d",&n);11 while(n--)12 {13 scanf("%I64d% 阅读全文
posted @ 2012-08-03 20:19 时光旅行的懒猫 阅读(239) 评论(0) 推荐(0)
摘要:题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2817快速幂取模问题套用模板就可以View Code 1 #include<stdio.h> 2 #include<string.h> 3 #define M 200907 4 __int64 quickpow(__int64 m,__int64 n) 5 { 6 int b=1; 7 while(n>0) 8 { 9 if(n&1)10 b=(b*m)%M;11 n=n>>1;//位运算 相当于n^212 m=... 阅读全文
posted @ 2012-08-03 19:59 时光旅行的懒猫 阅读(177) 评论(0) 推荐(0)
摘要:这两个是一个类型的题目。放在一块吧。题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1262View Code题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2098View Code 1 #include <stdio.h> 2 #include<math.h> 3 int jud(int n) 4 { int t=sqrt(n),i; 5 t++; 6 for(i=2;i<t;i++) 7 if(n%i==0) return 0; 8 return 1; 9 }10 int 阅读全文
posted @ 2012-08-03 17:57 时光旅行的懒猫 阅读(179) 评论(0) 推荐(0)