poj 2407——Relatives
来源:互联网 发布:js点击播放音频 编辑:程序博客网 时间:2024/06/13 15:51
题意:求欧拉函数
代码如下:
#include<iostream>#include<cstdio>#include<cstring>using namespace std;bool valid[50005];int ans[50005];int tot=0;void getPrime(){ int n=50000; memset(valid,true,sizeof(valid)); valid[1]=valid[0]=false; for(int i=2;i<n;++i) { if(valid[i]) { ans[tot++]=i; } for(int j=0;((j<tot)&&(i*ans[j]<=n));j++) { valid[i*ans[j]]=false; if(i%ans[j]==0)break; } }}int phi(int n){ int rea=n; for(int i=0;ans[i]*ans[i]<=n;++i) { if(n%ans[i]==0) { rea=rea-rea/ans[i]; while(n%ans[i]==0) { n/=ans[i]; } } } if(n>1) { rea=rea-rea/n; } return rea;}int main(){ // freopen("data.txt","r",stdin); getPrime(); int n; while(scanf("%d",&n)!=EOF && n) { printf("%d\n",phi(n)); } return 0;}
0 0
- poj 2407——Relatives
- poj 2407 Relatives
- POJ 2407 Relatives
- poj - 2407 - Relatives
- poj 2407 Relatives
- Poj 2407 Relatives
- poj 2407 Relatives
- POJ 2407 Relatives
- POJ 2407 Relatives
- poj 2407 Relatives
- poj 2407 Relatives
- poj 2407 Relatives
- POJ 2407 Relatives
- POJ 2407 Relatives
- POJ 2407 Relatives
- POJ 2407 Relatives
- POJ 2407 Relatives
- POJ 2407Relatives
- MySQL基本数据类型
- 2. Java 文件名与类名关系
- 初识hta
- 消费经济学
- 是:是否为此文本 20140705
- poj 2407——Relatives
- PHP 自幂数算法
- Linux中history历史命令使用方法详解
- ClientDataSet的用法
- Linux--编程--epoll
- OSX:视频-命令行制作OSX安装U盘
- 字典树 之 poj 1056
- pdf阅读器开发
- 素数判定 费马测试