HDU 5514 欧拉函数应用】的更多相关文章

前置技能: <=i且与i互质的数的和是phi(i)*i/2 思路: 显然每个人的步数是gcd(a[i],m) 把m的所有因数预处理出来 1~m-1中的每个数 只会被gcd(m,i)筛掉一遍 //By SiriusRen #include <cstdio> #include <algorithm> using namespace std; ; typedef long long ll; ; int gcd(int a,int b){return b?gcd(b,a%b):a;}…
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不会 就自己写了个容斥搞一下(才能维持现在的生活) //别人的题解https://blog.csdn.net/luyehao1/article/details/81672837 #include <iostream> #include <cstdio> #include <cstr…
Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 4904    Accepted Submission(s): 1631 Problem Description There are m stones lying on a circle, and n frogs are jumping over them.The stones…
Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 210    Accepted Submission(s): 57 Problem Description Lemon wants to be a hero since he was a child. Recently he is reading a book…
The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5235    Accepted Submission(s): 2225 Problem Description The Euler function phi is an important kind of function in number theo…
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15810    Accepted Submission(s): 4914 Problem Description Give a number n, find the minimum x(x>0) that satisfies 2^x mod n = 1.   I…
Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1071    Accepted Submission(s): 323 Problem Description an = X*an-1 + Y and Y mod (X-1) = 0.Your task is to cal…
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<math.h> 6 using namespace std; 7 typedef long long ll;…
裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int maxn=3000000+100; int phi[maxn]; void init() { for(int i=2;i<maxn;i++) phi[i]=i; for(int i=2;i<maxn;i++) i…
http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = N,我们枚举 gcd(A, N) = g,那么gcd(B, N) = N / g.问题转化为统计满足 gcd(A, N) = g 的 A 的个数.这个答案就是 ɸ(N/g) 只要枚举 N 的 约数就可以了.答案是 Σɸ(N/g)*ɸ(g) g | N 暴力即可 #include <cstdio>…