POJ 2407 Relatives && UVA 10299 Relative -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【meiwen.anslib.com - 电脑资料】

    【题目大意】:欧拉函数:求少于或等于n的数中与n互素的数的个数;n <= 1,000,000,000,

POJ 2407 Relatives && UVA 10299 Relative

    【思路】:裸欧拉函数,注意特判n==1的情况,n==1的情况下,应该输出0,poj依然判断1也可以过,但是老牌ojUVA必须是0才过,注意一下。

    代码:

#include<stdio.h>#include<string.h>#include<iostream>#include using namespace std;typedef long long LL;int eular(int n){    int res=n;    for(int i=2; i*i<=n; ++i){        if(n%i==0){            n/=i;res=res-res/i;            while(n%i==0)            {                n/=i;            }        }    }    if(n!=1) res=res-res/n;    return res;}int main(){    int n;while(cin>>n&&n!=0)    {        if(n==1) puts("0");        else printf("%d\n",eular(n));    } return 0;}</iostream></string.h></stdio.h>

    版权声明:本文为博主原创文章,未经博主允许不得转载,

电脑资料

POJ 2407 Relatives && UVA 10299 Relative》(http://meiwen.anslib.com)。

最新文章