zoukankan      html  css  js  c++  java
  • cf 13A

    A. Numbers
    time limit per test
    1 second
    memory limit per test
    64 megabytes
    input
    standard input
    output
    standard output

    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.

    Input

    Input contains one integer number A (3 ≤ A ≤ 1000).

    Output

    Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.

    Sample test(s)
    input
    5
    output
    7/3
    input
    3
    output
    2/1
    Note

    In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively.

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cstdlib>
    #include<cmath>
    #include<string>
    #include<algorithm>
    using namespace std;
    int n;
    int gcd(int x,int y)
    {
          if(y==0) return x;
          return gcd(y,x%y);
    }
    int main()
    {
          int x=0,y=0,z=0;
          scanf("%d",&n);
          for(int i=2;i<n;i++)
          {
                for(int j=n;j>0;j=j/i)
                {
                      x+=j%i;
                }
          }
          y=n-2;
          z=gcd(x,y);
          printf("%d/%d
    ",x/z,y/z);
          return 0;
    }
    

      

  • 相关阅读:
    [APIO2012]派遣
    Luogu_2774 方格取数问题
    Luogu4149 [IOI2011]Race
    Luogu_4886 快递员
    Loj_6282. 数列分块入门 6
    LOJ 6281 数列分块入门 5
    三维偏序 cdq
    【逆序对】 模板
    【luogu P1637 三元上升子序列】 题解
    【luogu P3609 [USACO17JAN]Hoof, Paper, Scissor蹄子剪刀布】 题解
  • 原文地址:https://www.cnblogs.com/a972290869/p/4219548.html
Copyright © 2011-2022 走看看