#12507: 逾時


0822_137934 (14306)

學校 : 臺北市私立延平高級中學
編號 : 60259
來源 : [119.14.210.98]
最後登入時間 :
2022-12-27 23:22:35
d440. 10299 - Relatives -- UVa10299 | From: [122.147.19.162] | 發表日期 : 2017-08-03 19:30

#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
long long int a;
while(cin>>a,a)
{long long int b=a;
for(int i=2;i<=a;i+=(i==2?1:2))
{if(a%i) continue;
b*=(1-1.0/i);
while(a%i==0) {a/=i;}
}
if(b==a){b--;}
cout<<b<<endl;
}
return 0;
}

請問如何改進?

 

 
#12508: Re:逾時


icube (!@#$%^&*()_+)

學校 : 國立臺灣師範大學附屬高級中學
編號 : 61090
來源 : [220.135.116.184]
最後登入時間 :
2024-04-01 14:01:32
d440. 10299 - Relatives -- UVa10299 | From: [220.135.116.184] | 發表日期 : 2017-08-03 20:06


http://acm.nudt.edu.cn/~twcourse/Euler'sPhiFunction.html

 
ZeroJudge Forum