数论
softrice
这个作者很懒,什么都没留下…
展开
-
HDU 4135——Co-prime
容斥原理 题意为输入a,b,n。找到区间[a,b]间与n互质的数的数量. 首先我们将n拆分成质因数. 利用容斥原理,答案就是b-a+1减去有奇数个质因子的数,加上有偶数个质因子的数. #include #include #include using namespace std; __int64 rec[6000000],k,ans,a,b,n,N; __int64 GCD(__int原创 2013-05-18 11:53:15 · 855 阅读 · 0 评论 -
二逼 普通 文艺的素数筛选法
二逼的素数筛选法 2b的筛选法,不多说。 const int N=1000000; bool pr[N]; int p[N],lp; bool isprime(int x){ for(int i=2;i*i<=x;i++) if(x%i==0) return 0; return 1; } void initp(){ for(int i=2;i<N原创 2013-05-18 16:15:32 · 931 阅读 · 0 评论 -
欧拉函数
Coach Yu has lots of bags, every bag has its number. And what is more, he wants to send these bags to acm team-member. But he requires that if you get the bag and its number is b, you need to count ho原创 2013-07-12 21:40:49 · 890 阅读 · 0 评论 -
约数个数
C - 1003 Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Description Let's denote d(n) as the原创 2013-08-05 14:08:33 · 816 阅读 · 0 评论 -
UVALive 6170
扩展欧几里德 #include #include #include using namespace std; typedef long long ll; ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b); } void _gcd(ll a,ll b,ll& d,ll& x,ll& y){ if(!b){ d原创 2013-10-03 22:23:28 · 997 阅读 · 0 评论 -
Codeforces Round #209 C - Prime Number
由于x是质数,所以约数肯定是X^k 这样的形式 注意trick点 :分子可能比分母还大,那么约数就是分母。 #include #include #include #include using namespace std; #define mod 1000000007 #define LL long long LL a[110000]; map bin; map::iterator原创 2013-11-03 13:07:04 · 871 阅读 · 0 评论