【纯欧拉函数】 poj 2407】的更多相关文章

#include <cstdio> #include <iostream> using namespace std; int phi(int x) { int t=x; ;i<=x;i++) { ) { t=t/i*(i-); x=x/i; } ) { x/=i; } } return t; } int main() { //freopen("in.txt","r",stdin); int n; ) { cout << ph…
题目链接: http://poj.org/problem?id=2407 题目大意:求小于n且与n互质的正整数个数. 解题思路: 欧拉函数=小于n且与n互质的正整数个数. 公式=n*(1-1/P1)*(1-1/P2)....*(1-1/Pn),其中Pn为不同的质因数. 欧拉函数的求法有好多. 最简单的是手艹质因数分解,然后套公式计算. 注意特判1的时候ans=0. #include "cstdio" #include "map" using namespace st…
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(&…
http://poj.org/problem?id=2407 题意:多组数据,每次输入一个数 ,求这个数的欧拉函数 int euler_phi(int n){//单个欧拉函数 int m=(int)sqrt(n+0.5); int ans=n; ;i<=m;i++)){ ans=ans/i*(i-); )n/=i; } )ans=ans/n*(n-); } 单个欧拉函数 int phi[maxn]; void phi_table(int n){//函数表 ;i<=n;i++)phi[i]=;…
Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 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 ther…
裸欧拉函数. #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]<…
题目链接 题意 : 求小于等于n中与n互质的数的个数. 思路 : 看数学的时候有一部分是将欧拉函数的,虽然我没怎么看懂,但是模板我记得了,所以直接套了一下模板. 这里是欧拉函数的简介. #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> using namespace std; int main() { int x…
题目链接 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 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…