poj 2407 Relatives(简单欧拉函数)】的更多相关文章

http://poj.org/problem?id=2407 题意: 给出一个n,求小于等于的n的数中与n互质的数有几个. 思路: 欧拉函数的作用就是用来求这个的. #include<iostream> #include<algorithm> #include<string> #include<cstring> #include<cmath> using namespace std; int n; int main() { //freopen(&…
Relatives Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are several t…
裸欧拉函数. #include<stdio.h> #include<string.h> ; int p[N],pr[N],cnt; void init(){ ;i<N;i++){ if(!p[i])pr[++cnt]=i; ;j<=cnt&&i*pr[j]<N;j++){ p[i*pr[j]]=; ) break; } } } int er(int n){ int ans=n; ;i<=cnt&&pr[i]*pr[i]<…
题目链接 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are se…
<题目链接> 题目大意: Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relatively prime if there are no integers x > 1, y > 0, z > 0 such that a = xy and b = xz. 解题分析: 其实只要看懂题目就会…
Relatives AC代码 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16186   Accepted: 8208 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers a and b are relativel…
http://poj.org/problem?id=2478 求欧拉函数的模板. 初涉欧拉函数,先学一学它主要的性质. 1.欧拉函数是求小于n且和n互质(包含1)的正整数的个数. 记为φ(n). 2.欧拉定理:若a与n互质.那么有a^φ(n) ≡ 1(mod n),经经常使用于求幂的模. 3.若p是一个质数,那么φ(p) = p-1.注意φ(1) = 1. 4.欧拉函数是积性函数: 若m与n互质,那么φ(nm) = φ(n) * φ(m). 若n = p^k且p为质数,那么φ(n) = p^k…
1.HDU 2824   The Euler function 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=2824 3.总结:欧拉函数 题意:求(a,b)间的欧拉函数值的和. #include<iostream> #include<cstring> #include<cmath> #include<queue> #include<algorithm> #include<cstdio>…
题目问有多少个小于n的正整数与n互质. 这个可以用容斥原理来解HDU4135.事实上这道题就是求欧拉函数$φ(n)$. $$φ(n)=n(1-1/p_1)(1-1/p_2)\dots(1-1/p_m)\tag{p为n的质因子}$$ 这个通项公式可以通过容斥原理的解法来验证.那么利用这个通项就能在$O(\sqrt[]n)$下计算出φ(n). #include<cstdio> #include<cstring> using namespace std; int phi(int n){…
/* * POJ_2407.cpp * * Created on: 2013年11月19日 * Author: Administrator */ #include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; const int maxn = 1000015; bool u[maxn]; ll su[maxn]; ll num; ll…