SGU102 Coprimes 程序

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;
}