# CodeForces-13A-Numbers

198人阅读 评论(0)

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.

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

* 以上用户言论只代表其个人观点，不代表CSDN网站的观点或立场
个人资料
• 访问：52980次
• 积分：4027
• 等级：
• 排名：第7698名
• 原创：370篇
• 转载：1篇
• 译文：0篇
• 评论：2条
阅读排行
评论排行
最新评论