poj2407
来源:互联网 发布:淘宝买猛将气输入什么 编辑:程序博客网 时间:2024/06/07 04:13
题目描述:
就是求小于它的互质的个数.但是是广泛定义.1相对于1也算有一个质数.
题解:
水
重点:
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <cmath>#include <ctype.h>#include <limits.h>#include <cstdlib>#include <algorithm>#include <vector>#include <queue>#include <map>#include <stack>#include <set>#include <bitset>#define CLR(a) memset(a, 0, sizeof(a))#define REP(i, a, b) for(int i = a;i < b;i++)#define REP_D(i, a, b) for(int i = a;i <= b;i++)typedef long long ll;using namespace std;const int maxn = 1e5 + 100;int p[maxn], pn;int vis[maxn];void getP(){ int key = 1e5 + 0.1; CLR(vis); pn = 0; for(int i = 2;i <= key;i++) { if(vis[i]==0) { p[pn++] = i; } for(int j = 0;j<pn&&p[j]*i<=key;j++) { int tmp = i*p[j]; if(i%p[j]==0) { break; } } }}int phi(int x){ int ans = x; int key = sqrt(x)+1e-10; for(int i = 0;p[i]<=key;i++) { if(x%p[i]==0) { ans = ans/p[i]*(p[i]-1); while(x%p[i]==0) { x /= p[i]; } } } if(x!=1) { ans = ans/x*(x-1); } return ans;}int main(){ // freopen("6Fin.txt", "r", stdin); //freopen("6Fout.txt", "w", stdout); int n; getP(); while(scanf("%d", &n)&&n!=0) { if(n != 1) printf("%d\n", phi(n)); else printf("1\n"); } return 0;}
0 0
- POJ2407
- poj2407
- poj2407
- poj2407
- poj2407
- poj2407-Relatives
- poj2407 Relatives
- [POJ2407] Relatives
- POJ2407 Relatives
- Relatives【POJ2407】
- poj2407 Relatives
- POJ2407 Relatives
- [POJ2407]Relatives
- poj2407解题报告
- poj2407 欧拉函数
- POJ2407 欧拉函数
- poj2407——水题
- 书架(贪心,POJ2407)
- div设置display:inline-block属性产生空白间距
- C/C++语言获取系统时间的几种方式 !
- chrome浏览器支持的最小字体为12px
- 《C语言及程序设计》实践参考——处理C语言源代码的程序
- 源码奉送:宠物小精灵图鉴
- poj2407
- js定义的变量不生效 - - 浏览器预定义
- Unity中的mvc框架_StrangeIoC(之二)
- Oracle 面向对象
- Arduino的串口
- js对象操作
- 设置渐变的背景色
- iOS 编程 计算字符串文字宽度
- springmvc接收和处理json数据