zoukankan      html  css  js  c++  java
  • 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
    ",ans/t,(A-2)/t);
    
        return 0;
    }
  • 相关阅读:
    表格的增删改查
    选择省份时,自动显示对应省份的城市
    弹框提示用户输入
    dom
    css基础
    HTML基础
    B
    poj 1840 Eqs
    hdu 1166 敌兵布阵(线段树)
    poj 2586 Y2K Accounting Bug
  • 原文地址:https://www.cnblogs.com/fish7/p/4317926.html
Copyright © 2011-2022 走看看