POJ 2407 Relatives && UVA 10299 Relative -電腦資料

電腦資料 時(shí)間:2019-01-01 我要投稿
【clearvueentertainment.com - 電腦資料】

    【題目大意】:歐拉函數(shù):求少于或等于n的數(shù)中與n互素的數(shù)的個(gè)數(shù);n <= 1,000,000,000,

POJ 2407 Relatives && UVA 10299 Relative

。

    【思路】:裸歐拉函數(shù),注意特判n==1的情況,n==1的情況下,應(yīng)該輸出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>

    版權(quán)聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉(zhuǎn)載,

電腦資料

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

最新文章