题意:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number A written in all bases from 2 to A - 1.
Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10.
思路:
直接,,,
代码:
int A; int gcd(int a,int b){ if(b==0){ return a; } return gcd(b,a%b); } int calc(int base){ int ret=0; int X=A; while(X){ ret+=(X%base); X/=base; } return ret; } int main(){ cin>>A; int ans=0; rep(i,2,A-1){ ans+=calc(i); } int t=gcd(ans,A-2); printf("%d/%d ",ans/t,(A-2)/t); return 0; }