FOJ 1012 Relatives(欧拉值)
来源:互联网 发布:android 监听网络断开 编辑:程序博客网 时间:2024/06/05 17:46
Problem 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 integersx > 1, y > 0, z > 0 such that a = xy and b = xz.
There are several test cases. For each test case, standard input contains a line withn <= 1,000,000,000. A line containing 0 follows the last case.
For each test case there should be single line of output answering the question posed above.
Sample Input
7120
Sample Output
64
这道题就是求比一个数小又和这个数互质的个数,就是欧拉值,这是前人已经推导出来了;
phi=n/(P1)*(P1-1)/P2*(P2-1)....../(Pn-1)*(Pn-1 - 1)/Pn*(Pn - 1),带公式就行;P是素因子
AC代码:
# include <stdio.h> # include <math.h># include <stdlib.h>int euler_phi(int n){int m=sqrt(n+0.5);int ans=n;for(int i=2; i<=m; i++){if(n%i==0){ans=ans/i*(i-1);}while(n%i==0){n=n/i;}}if(n>1)ans=ans/n*(n-1);return ans;}int main(){int n;while(scanf("%d", &n)){if(n==0){break;}printf("%d\n", euler_phi(n));}return 0;}
0 0
- FOJ 1012 Relatives(欧拉值)
- FOJ 1012 Relatives
- FZU 1012 Relatives
- Relatives
- Relatives
- Relatives
- JOJ1874:Relatives
- pku2407 Relatives
- poj2407-Relatives
- poj2407 Relatives
- [POJ2407] Relatives
- POJ2407 Relatives
- Relatives【POJ2407】
- poj2407 Relatives
- POJ2407 Relatives
- [POJ2407]Relatives
- FOJ 1012 欧拉函数水题
- FOJ月赛被虐
- Android 初学 图片切换 Image switching and showing
- 讯飞语音合成_1_环境搭建
- 二分图,匈牙利算法,hdu2063
- 这个是自己的第一篇博客,从现在开始自己就已经走出了校园,正式成为了一名即将工作的程序员了
- 数据库事务
- FOJ 1012 Relatives(欧拉值)
- 初学射极跟随器2
- 字节流与字符流的区别详解
- POJ1118 HDU1432 Lining Up
- HDU1556
- 读《About Face 4 交互设计精髓》3
- iOS深入学习(Block全面分析)
- mysql复合语句、存储过程、游标
- lightoj1058 && poj1791 求平行四边形个数