CodeForces-13A-Numbers

原创 2016年05月31日 22:20:55

Appoint description:

Description

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 Input
Input

5

Output

7/3

Input

3

Output

2/1

Hint

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.

这道题目有点小意思,意思就是算2到n-1进制的个位数和,然后与n-2求gcd就OK了

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;

int gcd(int a, int b)
{
    if (a%b == 0)
    {
        return b;
    }
    return gcd(b, a%b);
}

int main()
{
    int n, z = 0, x, y, sum, m;
    scanf("%d", &n);
    for (int j = 2; j<n; j++)
    {
        sum = 0;
        m = n;
        while (m)
        {
            sum += (m%j);
            m /= j;
        }
        z += sum;
    }
    x = gcd(z, n - 2);
    z = z / x;
    y = (n - 2) / x;
    printf("%d/%d\n", z, y);
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。

Educational Codeforces Round 13 A.Johny Likes Numbers && B. The Same Calendar

传送门 A. Johny Likes Numbers time limit per test0.5 seconds memory limit per test256 megabytes inp...

【动态规划】【数位DP】[Codeforces 55 D]Beautiful numbers

题目描述Volodya is an odd boy and his taste is strange as well. It seems to him that a positive integer ...

codeforces-55D-Beautiful numbers(数位DP)

 A - Beautiful numbers Time Limit:4000MS     Memory Limit:262144KB     64bit IO Format:%...

【Codeforces 817 C. Really Big Numbers】+ 构造

C. Really Big Numbers time limit per test1 second memory limit per test256 megabytes inputstandar...

Codeforces Round #235 (Div. 2) D. Roman and Numbers(状压dp)

Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes ...

Codeforces Round #136 (Div. 2) / 221B Little Elephant and Numbers (数论)

a

Codeforces Round #226 (Div. 2)--C. Bear and Prime Numbers

C. Bear and Prime Numbers time limit per test 2 seconds memory limit per test 512 megaby...

【打CF,学算法——二星级】CodeForces 96B Lucky Numbers (构造/dfs)

题目链接:CF 96B 题面: B. Lucky Numbers (easy) time limit per test 2 seconds memory limit per t...

Codeforces Round #FF (Div. 2) E. DZY Loves Fibonacci Numbers(斐波那契的定理+线段树)

/*   充分利用了菲波那切数列的两条定理:    ①定义F[1] = a, F[2] = b, F[n] = F[n - 1] + F[n - 2](n≥3)。         有F[n] =...

codeforces 414A Mashmokh and Numbers 模拟题

Description It’s holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.In...
  • wilver
  • wilver
  • 2015年12月01日 20:58
  • 173
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CodeForces-13A-Numbers
举报原因:
原因补充:

(最多只允许输入30个字)