欧拉函数
来源:互联网 发布:nfc世界网络银行商城 编辑:程序博客网 时间:2024/05/10 00:20
Counting fractions
TimeLimit: 2000MS MemoryLimit: 65536 Kb
Totalsubmit: 26 Accepted: 4
Description
Consider the fraction, n/d, where n and d are positive integers. If n <= d and HCF(n,d)=1, it is called a reduced proper fraction.
If we list the set of reduced proper fractions for d <= 8 in ascending order of size, we get:
1/8, 1/7, 1/6, 1/5, 1/4, 2/7, 1/3, 3/8, 2/5, 3/7, 1/2, 4/7, 3/5, 5/8, 2/3, 5/7, 3/4, 4/5, 5/6, 6/7, 7/8
It can be seen that there are 21 elements in this set.
How many elements would be contained in the set of reduced proper fractions for d <= x?
Input
The input will consist of a series of x, 1 < x < 1000001.
Output
For each input integer x, you should output the number of elements contained in the set of reduced proper fractions for d <= x in one line.
Sample Input
3
8
Sample Output
3
21
//题目大意是求前n个数的所有与其的个数,即可以分为求1,2,3。。。到n的与其互质的个数 //如果n为素数的话,那么与n互质的个数为n-1 //如果n不为素数的话,那么n的质因子与n不互质,并且小于n的质因子的倍数也与n不互质,//假设a为n的质因子的话,那么关于a的倍数与n互质的个数为n/a;//所以题意转换为分别求n的质因子,然后用n-n/a #include<iostream> #include<string>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>#include<stack>#include<vector>#include<climits>using namespace std; #define rep(i,n) for(i=0; i<(n); i++)#define repf(i,n,m) for(i=(n); i<=(m); i++)//正循环的#define repd(i,n,m) for(i=(n); i>=(m); i--) //负循环的 #define fab(a) (a)>0?(a):0-(a)#define max(a,b) (a)>(b)?(a):(b)#define min(a,b) (a)<(b)?(a):(b)#define ll __int64#define arc(a) (a)*(a)#define inf 1000000 //最大值的#define exp 0.0000001 //浮点型的#define N 1000005 //记录开的数组bool vis[N];int prime[N]; ll num[N];int main(){ int i,j; memset(vis,true,sizeof(vis)); repf(i,1,inf) num[i]=i; repf(i,2,inf) { if(vis[i]==true)//为质因子,找到质因子什么东西的 { num[i]--; for(j=i+i; j<=inf; j+=i) { vis[j]=false; num[j]-=num[j]/i; } } } printf("%d\n",num[8]); repf(i,3,inf) { num[i]+=num[i-1]; } int n; while(~scanf("%d",&n)) cout<<num[n]<<endl; return 0;}
- 欧拉函数
- 欧拉函数
- Relatives 【欧拉函数】
- 欧拉函数
- POJ_2407_欧拉函数
- 欧拉函数
- hdu_3501_欧拉函数
- 欧拉函数
- 欧拉函数
- 欧拉函数
- 欧拉函数
- 欧拉函数
- 欧拉函数
- 欧拉函数应用
- 欧拉函数
- 欧拉函数
- 欧拉函数
- ACM-欧拉函数
- 简单c语言实现unix shell【转载】
- 黑马程序员----JAVA基础之 BeanUtils
- ios 加速传感器UIAccelerometer
- 软件设计模式系列之二 FACTORY METHOD(工厂方法)
- JQuery操作Dom
- 欧拉函数
- hdu 4027 Can you answer these queries? 线段树 懒惰标记 单点更新妙用
- 从微信谈起,如何优化互联网APP心跳机制
- 决策树(decisions tree)和ID3算法
- uva 11461(水题)
- WINCE音量设置(系统音按键音)
- JQuery基本过滤选择器与表单对象过滤器
- 怎么在vs2005中加入wince5 模拟器
- AsyncQueryHandler学习