码迷,mamicode.com
首页 > 其他好文 > 详细

cf13A Numbers(,,)

时间:2015-03-06 14:04:11      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

题意:

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\n",ans/t,(A-2)/t);

    return 0;
}

 

cf13A Numbers(,,)

标签:

原文地址:http://www.cnblogs.com/fish7/p/4317926.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!