Feb
11
SGU 102 Coprimes 程序
2007 解题报告 Popularity: 1%
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | //AC #include <iostream> using namespace std; bool gcd(int a,int b) { int t=0; while (b>0) { t=b; b=a%b; a=t; } return (a==1); } int main() { int n,c=0; cin>>n; for (int i=n-2;i>0;--i) if (gcd(n,i)) ++c; cout<<c+1<<endl; return 0; } |
- http://www.briefdream.com/sgu-102/
- Tags:SGU, 最大公约数
- (0)comments | leave a reply
- Trackback URI