Codeforces Numbers 题解

这题只需要会10转P进制就行了。

PS:答案需要约分,可以直接用c++自带函数__gcd(x,y)。

洛谷网址

Codeforces网址

Code(C++): 

#include<bits/stdc++.h>
using namespace std;
int jz(int x,int p) {
     int s=0,a;
     while(x>0) {//10转P进制
         a=x%p;
         s+=a;//直接将算出的哪一位加上
         x/=p;
     }
     return s;
}
int main() {
     int A,x=0;
     cin>>A;
     int y=A-2;
     for(int i=2;i<A;i++) {//循环从2到A-1
         int t=jz(A,i);
         x+=t;
     }
     int d=__gcd(x,y);//最大公约数函数
     x/=d;y/=d;//约分
     cout<<x<<"/"<<y<<endl;
     return 0;
}
原文地址:https://www.cnblogs.com/Ryan-juruo/p/11382463.html