POJ 2407

裸 的求欧拉函数

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int n;
	while(scanf("%d",&n),n){
		int res=n;
		int L=(int)sqrt(n*1.0);
	//	cout<<L<<endl;
		for(int i=2;i<=L;i++){
			if(n%i==0){
			//	cout<<i<<endl;
				res=res-res/i;
				while(n%i==0)
				n/=i;
			//	cout<<n<<endl;
			}
		}
		if(n>1)
		res=res-res/n;
		printf("%d\n",res);
	}
	return 0;
}

  

时间: 2024-12-17 01:10:50

POJ 2407的相关文章

[POJ 2407]Relatives(欧拉函数)

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 integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are several

POJ 2407 Relatives 欧拉函数题解

最基本的欧拉函数: 欧拉函数:求小于n的与n互质的个数 欧兰函数公式:φ(x)=x(1-1/p1)(1-1/p2)(1-1/p3)(1-1/p4)-..(1-1/pn),其中p1, p2--pn为x的所有质因数 就是要求这样的式子啦,不过求这条式子,相信有很多种方法可以求,这个不是难题: 不过问题是如何巧妙地求,如何简洁地写出代码. 直接硬求,或者求出质因数之后求都不是巧妙的方法了,参考了下别人的代码才知道可以写的这么巧妙的. 下面程序可以说是连消带打地求式子结果,分解质因子,可以如此简明地把解

Poj(2407),Greater New York Regional 2015 (D)

题目链接:http://poj.org/problem?id=2407 Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13599   Accepted: 6772 Description Given n, a positive integer, how many positive integers less than n are relatively prime to n? Two integers

POJ 2407 Relatives &amp;&amp; UVA 10299 Relatives(欧拉函数)

[题目链接]:click here~~ [题目大意]:欧拉函数:求少于或等于n的数中与n互素的数的个数:n <= 1,000,000,000. [思路]:裸欧拉函数,注意特判n==1的情况,n==1的情况下,应该输出0,poj依然判断1也可以过,但是老牌ojUVA必须是0才过,注意一下. 代码: #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm>

POJ 2407 Relatives

Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13920   Accepted: 6965 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 i

数论 - 欧拉函数模板题 --- poj 2407 : Relatives

Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11372   Accepted: 5544 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 ther

POJ 2407 Relatives(欧拉函数)

Relatives Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11801   Accepted: 5780 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 ther

poj 2407 Relatives(简单欧拉函数)

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 integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are several

POJ 2407 Relatives(欧拉函数入门题)

Relatives 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 integers x > 1, y > 0, z > 0 such that a = xy and b = xz. Input There are several t