随笔分类 - ACM---数论
数论。
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4067美丽的花环Time Limit:1000msCase Time Limit:1000msMemory Limit:65536KBSpecial Judge64-bit integer IO format:%lld Java class name:MainSubmitStatusFont Size:+-学校的草坪上最近种植了一些漂亮的花卉,所有的花围成了一个环形(内径为r,外径为R,0 7 #include 8 #include 9 #include10 using namespace st.
阅读全文
摘要:Prime TestTime Limit:6000MSMemory Limit:65536KTotal Submissions:27129Accepted:6713Case Time Limit:4000MSDescriptionGiven a big integer number, you are required to find out whether it's a prime number.InputThe first line contains the number of test cases T (1 10 #include 11 #include 12 #include 1
阅读全文
摘要:1 //**************************************************************** 2 // Miller_Rabin 算法进行素数测试 3 //速度快,而且可以判断 =mod)19 ans=ans-mod;20 }21 a=a=mod) a=a-mod;23 b=b>>1;24 }25 return ans;26 }27 28 LL pow_mod(LL a,LL b,LL mod) // a^b%mod29 {30 LL ans=1;31 ...
阅读全文
摘要:1 //************************************************ 2 //pollard_rho 算法进行质因数分解 3 //************************************************ 4 5 LL factor[100];//质因数分解结果(刚返回时是无序的) 6 int tol;////质因数的个数。数组小标从0开始 7 8 LL gcd(LL a,LL b) 9 {10 if(a==0) return 1;// !!!!11 if(a=n)48 p=Pollard_rho(p,r...
阅读全文
摘要:DivisorsTime Limit:1000MSMemory Limit:65536KTotal Submissions:9617Accepted:2821DescriptionYour task in this problem is to determine the number of divisors ofCnk. Just for fun -- or do you need any special reason for such a useful computation?InputThe input consists of several instances. Each instanc
阅读全文
摘要:http://acm.sdibt.edu.cn/JudgeOnline/problem.php?id=3232Problem C:A^X mod PTime Limit: 5 SecMemory Limit: 128 MBSubmit: 10Solved: 2[Submit][Status][Discuss]DescriptionIt's easy for ACMer to calculate A^X mod P. Now given seven integers n, A, K, a, b, m, P, and a function f(x) which defined as fol
阅读全文
摘要:Problem 1752 A^B mod CAccept: 579Submit: 2598Time Limit: 1000 mSecMemory Limit : 32768 KB Problem DescriptionGiven A,B,C, You should quickly calculate the result of A^B mod C. (1 5 #include 6 #include 7 #include 8 using namespace std; 9 10 11 12 unsigned __int64 mgml(unsigned __int64 a,unsigned __i.
阅读全文
摘要:阶乘因式分解(一)时间限制:3000ms | 内存限制:65535KB难度:2描述给定两个数m,n,其中m是一个素数。将n(0 2 3 int Euler(int n,int m) 4 { 5 int k=0; 6 while(n) 7 { 8 n=n/m; 9 k=k+n;10 }11 return k;12 }13 14 int main()15 {16 int T,n,m;17 while(scanf("%d",&T)>0)18 {19 while(T--)20 ...
阅读全文
摘要:因子和阶乘时间限制:1000ms | 内存限制:65535KB难度:2http://acm.nyist.net/JudgeOnline/problem.php?pid=509描述给你一个正整数n,把n!=1x2x3x.....xn分解成素因子相乘的形式,并从小到大输出每个素因子的指数,但要保证最后输出的素因子个数不为0。例如825应表示为0,1,2,0,1表示分别有0,1,2,0,1个2,3,5,7,11。输入第一行有一个整数n(0N/p1^1+(N/p1^1)/p1^1+((N/p1^1)/p1^1)/p1^1;这样的话就可以写成一个solve函数。 1 #include 2 #includ
阅读全文
摘要:Problem 1075 分解素因子Accept: 1331Submit: 2523Time Limit: 1000 mSecMemory Limit : 32768 KB Problem Description假设x是一个正整数,它的值不超过65535(即1 7 #include 8 9 void Euler(int n)10 {11 int i,k=0;12 for(i=2;i*i0)39 {40 while(n--)41 {42 scanf("%d",&m);43 Euler(m);...
阅读全文
摘要:理论依据:代码: 1 /* 2 显然,数据够大的时候,数组要用 __int64 3 4 */ 5 6 #include 7 #include 8 #include 9 #include10 #include11 12 using namespace std;13 14 15 bool s[1000003];16 int num[1000003];//用来%j17 int ans[1000003];//保存和。18 19 void make_ini() //全部扫一遍。筛选一下。20 {21 int i,j,k,t;22 for(i=1;i0)53 {54 ...
阅读全文
摘要:Very Simple CountingTime Limit: 1 Second Memory Limit: 32768 KBLet f(n) be the number of factors of integer n.Your task is to count the number of i(1 4 #include 5 6 int f[1000003]; 7 int Num_Euler(int n) 8 { 9 int num=1,k,i;10 for(i=2;i*i0)37 {38 num=0;39 for(i=1;i 2 #...
阅读全文
摘要:Problem 1607 Greedy divisionhttp://acm.fzu.edu.cn/problem.php?pid=1607Accept: 402Submit: 1463Time Limit: 1000 mSecMemory Limit : 32768 KB Problem DescriptionOaiei has inherited a large sum of wealth recently; this treasure has n pieces of golden coins. Unfortunately, oaiei can not own this wealth al
阅读全文
摘要:/*二进制求最大公约数。由于传统的GCD,使用了%,在计算机运行过程中要花费大量的时间,所以,采取二进制的求法,来减少时间的消耗。算法:当a,b都是偶数时: gcd(a,b)=2*gcd(a/2,b/2);当a,b一奇一偶时: if(a&1) gcd(a,b)=gcd(a,b/2); else gcd(a,b)=gcd(a/2,b);当a,b都是奇数时: if(a>b) gcd(a,b)=gcd( (a-b)/2, b); else gcd(a,b)=gcd( a,(b-a)/2);其实就是把偶数的/2,而且奇数-奇数=偶数。*/ 1 #include 2 3 int Binar
阅读全文
摘要:Primitive RootsTime Limit:1000MSMemory Limit:10000KTotal Submissions:2479Accepted:1385DescriptionWe say that integer x, 0 10 11 12 int Euler(int n)13 {14 int i,temp=n;15 for(i=2;i*i0)33 {34 printf("%d\n",Euler(n-1));35 }36 return 0;37 }
阅读全文
摘要:Happy 2006Time Limit:3000MSMemory Limit:65536KTotal Submissions:8359Accepted:2737DescriptionTwo positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9...are all relatively prime to 2006.Now your job is easy: for the given i
阅读全文
摘要:Longge's problemTime Limit:1000MSMemory Limit:65536KTotal Submissions:6383Accepted:2043DescriptionLongge is good at mathematics and he likes to think about hard mathematical problems which will be solved by some graceful algorithms. Now a problem comes: Given an integer N(1 20 #include21 #includ
阅读全文
摘要:GCDTime Limit: 6000/3000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4141Accepted Submission(s): 1441Problem Descrip...
阅读全文
摘要:Co-primeTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 935Accepted Submission(s): 339Problem DescriptionGiven a number N, you are asked to count the number of integers between A and B inclusive which are relatively prime to N.Two integers are said
阅读全文
摘要:NumberTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2159Accepted Submission(s): 614Problem Description Here are two numbers A and B (0 x : ans 1-1:0 1-2:0 1-3:0 1-4:0 1-5:0//x小于等于5之前都是0。5/2-2 = 0 1-6:1//x是某个数的平方和,且k为偶数。则不变 6/2-2 = 1; 1-7:1//x是某个.
阅读全文
浙公网安备 33010602011771号