摘要:算法:利用数据1...N的性质,求与P的互质的个数,位运算,容斥定理。。#include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace std;struct info{ int s,e
阅读全文
摘要:算法:N = (1+p1)*(1+p2) *(1+p3)...*(1+pn)View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace std;int n, a
阅读全文
摘要:题目1207:质因数的个数时间限制:1 秒内存限制:32 兆特殊判题:否提交:1397解决:326题目描述:求正整数N(N>1)的质因数的个数。相同的质因数需要重复计算。如120=2*2*2*3*5,共有5个质因数。输入:可能有多组测试数据,每组测试数据的输入是一个正整数N,(1<N<10^9)。算法:只要筛选出sqrt(1000000000)前面的素数即可。代码:View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#i
阅读全文
摘要:题目描述:给定n,a求最大的k,使n!可以被a^k整除但不能被a^(k+1)整除。输入:两个整数n(2<=n<=1000),a(2<=a<=1000)算法:分解N!和a 的因子...是否整除就看因子是否包含。。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<
阅读全文
摘要:奇葩的算法View Code #include<iostream>#include<cstdio>#include<cstdlib>#include<algorithm>#include<cmath>#include<queue>#include<set>#include<map>#include<cstring>#include<vector>#define LL unsigned long longusing namespace std;LL p[10] = { 2,3,
阅读全文
摘要:题意:一个有限数数从A进制转换为B进制,如果依然是有限数输出YES,否则NO算法:只要检查A中的质因子 是否都在 B中被包含。刚开始二了,分别把每个数分解质因数,然后二分查找是否存在果断TLE。分解A的质数prime[i]时,就用B%prime[i]判断是否整除。。。同时进行View Code #include<stdio.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map
阅读全文
摘要:数字游戏续Time Limit : 12000/4000ms (Java/Other)Memory Limit : 65535/32768K (Java/Other)Total Submission(s) : 152Accepted Submission(s) : 50Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem Description自从小艾上次在和小牛的游戏中取得了信心之后,这次他又想到了一个问题,他要去计算两个数A和B的最大公约数。由于这两个数非常的大,于是小牛把数字A拆成了N个数,这N个数相乘的结果是A,把B拆成了M个数
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <vector>#include <deque>using namespace std;const int inf = 0x7f7f7f7f;struct node { int x, v; }Nd;int N1,M1,P1,f1;vector<node>T[11010];deque<int>q;bool flag[11010] = {false};int dis[11020];int
阅读全文
摘要:Burn the Linked CampTime Limit: 1 Second Memory Limit: 32768 KBIt is well known that, in the period of The Three Empires, Liu Bei, the emperor of the Shu Empire, was defeated by Lu Xun, a general of the Wu Empire. The defeat was due to Liu Bei's wrong decision that he divided his large troops in
阅读全文
摘要:1575: 素因子Time Limit: 5 SecMemory Limit: 128 MBSubmit: 254Solved: 102[Submit][Status][Web Board]Description我们知道,任何一个大于1的数,都可以写成多个素数的乘积,我们把这些素数叫做这个数的素因子。Input第一行为测试数据的组数N,以下N行,每行一个数字k(1<k<2^24)Output输出N行,每行两个数字,一个是k的最大素因子,第二个是k的素因子的个数。Sample Input31025120Sample Output5 25 15 3#include <stdio.
阅读全文
摘要:A - Goldbach's ConjectureTime Limit: 1000MSMemory Limit: 65536K64bit IO Format: %I64d & %I64u [Submit] [Go Back] [Status] DescriptionIn 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in which he made the following conjecture: Every even number great
阅读全文
摘要:1098: 素MMTime Limit: 1 SecMemory Limit: 128 MBSubmit: 52Solved: 30[Submit][Status][Web Board]Description素数有很多神奇的性质,所以很美。我们知道一个日期将年、月、日按顺序连接在一起可以组成一个八位数,例如2011年3月6日可以写成20110306。我的某个MM的生日组成的数是一个素数。偶尔我叫她素MM,没人知道是啥意思,她自己也不知道。O(∩_∩)O哈哈~我心里可是真的美美的(⊙o⊙)哦! 嗯,什么?你的生日也是素数?你也想做“素MM”或者“素GG”?那好吧,不过我可是很小气的哦!只有你出生
阅读全文
摘要:用普通的筛法,1000 0000 的数,需要用时1600ms左右。#include <stdio.h>#include <string.h>#include <math.h> char dp[10000010]; const int inf = 10000001;int t = sqrt(inf); inline void prime ( ){ int i, j, k = 0,p; dp[1] = -1; for (i = 2; i <= t; i++) if( dp[i] != -1) { //p = inf / i; for (j = 2; j &
阅读全文
摘要:扩展欧几里德1.定义:扩展欧几里德定理 对于不完全为 0 的非负整数 a,b,gcd(a,b)表示 a,b 的最大公约数,必然存在整数对 x,y ,使得 gcd(a,b)=ax+by。2.c语言实现#include <stdio.h>int q,x, y;void swap ( int *x1, int *y1){ int temp; temp = *x1; *x1 = *y1; *y1 = temp;} void fun( int a, int b){ if (b == 0 ) { x = 1; y = 0; q = a; } else { fun ( b, a % b); in
阅读全文
摘要:1.同余定义:设两个整数a, b,正整数m, m | a - b, 即 m * c = k ( a - b),则称a 模m同余于b, 或a 与b 模m 同余,记做 a = b (mod m).2.同余性质:1) 自反性2) 传递性3) 对称性4) 若 a = b (mod m), c = d (mod m)则 a+b = b+ d(mod m) a - b= b - d(mod m) ac = bd (mod m);3.中国剩余定理CRT (中国剩余定理CRT)设m1,m2,...,mk是两两互素的正整数,即gcd(mi, mj) =1, i≠j, i,j = 1,2,...,k 则同余方程组
阅读全文
摘要:1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <math.h> 4 #include <string.h> 5 6 int A[400000]; 7 8 int prime(int N) 9 {10 int i, j, k = 0;11 12 for (i = 2; i < N ; i++) {13 if (N % i == 0 ) {14 for (j = i; j < N; j += i)15 A[j] = 1;16 }17 }18 for (i = 1; i <
阅读全文
摘要:1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <math.h> 5 6 int A[80000], dp[20000]; 7 8 const int inf = 65535; 9 10 int prime( )11 {12 int i, j, k = 0;13 A[1] = 1;14 for( i = 2; i <= sqrt(inf); i++)15 for ( j = 2 * i; j <= inf; j += i)16 A[
阅读全文
摘要:数论学习之素数1.相关定义:整除: 设a, b是两个整数,且b != 0 如果存在整数c ,使 a = bc, 则称a被b整除, 或b 整除a , 记作b|a;带余除法:a = qb + r;这个式子称为带余除法 记余数 r = a mod b;2.整除性质1. 如果a |b 且 a | c,则对任意正整数x, y ,有a | bx + c y;2.如果 a| b 且 b|c, 则a | c;3.设m != 0,则a | b,当且仅当 ma | mb;4.如果 a | b且b | a,则a = +_b;5.如果a| b,且 b!= 0,则 |a| <= |b|;3.素数定义:如果正整数a
阅读全文
摘要:数论学习之最大公约数与最小公倍数最大公约数 定义:设a,b是两个整数,如果d|a,且d|b,则称d是a和b的公因子,或公约数,除0之外,任和整数只有有限个因子,其中最大的叫做最大公约数。 记做: gcd( a, b)最小公倍数 定义:设a, b 是两个整数,如果a|d,b|d,则称d是a,b的公倍数,a,b的公倍数有无穷个,最小的那个称做最小公倍数。 记做 :lcm (a,b); 显然对于任意的正整数a:gcd(0,a) = a; gcd(1,a)=1; lcm(1,a) = a;最小公倍数与最大公约的数两条性质:1.a|m , b|m, lcm(a,b) l m;2.m|a,m|b, m |
阅读全文