Numbers
Problem 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
5
Sample Output
7/3
Sample Input
3
Sample 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.
题意
求出A按照2到A-1进制得出来的个位数只和的平均数
方法
如题意,暴力即可
代码
#include<cstdio>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdlib>
#include<iomanip>
#include<string>
#include<vector>
#include<map>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define INF 0x3f3f3f3f
typedef long long ll;
int main()
{
int n;
cin>>n;
int i;
int sum=0;
int z=0;
for(i=2;i<=n-1;i++)
{
z=0;
int m=n;
while(m)
{
z=z+m%i;
m=m/i;
}
sum=sum+z;
}
int kk;
kk=__gcd(sum,n-2);
printf("%d/%d\n",sum/kk,(n-2)/kk);
}