HDU1286新朋友欧拉函数版
2016-04-23 19:23
302 查看
找新朋友
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10401 Accepted Submission(s):
5493
[align=left]Problem Description[/align]
新年快到了,“猪头帮协会”准备搞一个聚会,已经知道现有会员N人,把会员从1到N编号,其中会长的号码是N号,凡是和会长是老朋友的,那么该会员的号码肯定和N有大于1的公约数,否则都是新朋友,现在会长想知道究竟有几个新朋友?请你编程序帮会长计算出来。
[align=left]Input[/align]
第一行是测试数据的组数CN(Case
number,1<CN<10000),接着有CN行正整数N(1<n<32768),表示会员人数。
[align=left]Output[/align]
对于每一个N,输出一行新朋友的人数,这样共有CN行输出。
[align=left]Sample Input[/align]
2
25608
24027
[align=left]Sample Output[/align]
7680
16016
[align=left]Author[/align]
SmallBeer(CML)
[align=left]Source[/align]
杭电ACM集训队训练赛(VII)
[align=left]Recommend[/align]
lcy | We have carefully selected several similar
problems for you: 1215 1406 1164 1787 1211
i代表质数 非质数不跑 res代表剩下的数 就是答案的数 x代表质因子分解的数 从x中分解出质因子进行运用
用完2要把2的倍数去掉所以有while那句话。
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> using namespace std; int euler(int x) {// 就是公式 int i, res=x; for (i = 2; i < (int)sqrt(x * 1.0) + 1; i++) if(x%i==0) { cout<<"start i:"<<i<<" res:"<<res<<" x:"<<x<<endl; res = res / i * (i - 1); cout<<"delete i:"<<i<<" res:"<<res<<" x:"<<x<<endl; while (x % i == 0) {x /= i;cout<<"x%i==0 i:"<<i<<" res:"<<res<<" x:"<<x<<endl;} // 保证i一定是素数 cout<<endl; } if (x > 1) {res = res / x * (x - 1);cout<<"end i:"<<i<<" res:"<<res<<" x:"<<x<<endl;} return res; } int main() { int n,t; cin>>t; while(t--) {cin>>n; cout<<euler(n)<<endl;} return 0; }
相关文章推荐
- 每天一个linux命令(15):tail命令
- Turn the corner
- win10+qt5.6.0+qtcreator3.6.1+mingw4.9.2+opencv4.8.12环境安装
- hibernate c3p0 连接无法释放 阻塞数据库操作
- BigDecimal用法详解
- Android:自定义Material Design风格的Dialog
- HDU1267 递推
- 非递归实现遍历二叉树
- IDE调试
- 站立会议5
- cpu阿甘
- 1017
- HDU1250 高精度斐波那契数列
- 1016
- 使用Retrofit2.0实现Google Drive文件上传进度显示
- UVA - 10878 Decode the tape
- shell变量详解
- HDU1130 卡特兰数
- 莫比乌斯反演
- Java.util.Date类型时间的减法