cf13A Numbers(,,)

题意:

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

 

转载于:https://www.cnblogs.com/fish7/p/4317926.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值