codefores 13A(进制数和最大公约数)

C - Numbers
Crawling in process... Crawling failed Time Limit:1000MSMemory Limit:65536KB 64bit IO Format:%I64d & %I64u

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», whereX is the numerator and Y is the denominator.

Sample Input

Input
5
Output
7/3
Input
3
Output
2/1

Sample Output

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<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
int GCD(int m,int n){  
	if(m>n) swap(m,n);  
	int r=n,a,b;  
	while(m>0){  
		r=n%m;  
		n=m;  
		m=r;  
	}  
	return n;  
}  
int count( int x,int jinzhi){
	int ret=0;
	while(x>0){
		ret+=x%jinzhi;
		x/=jinzhi;
	}
	return ret;
}
int main(){
	int n;
	while(scanf("%d",&n)!=EOF){		
		int sum=0;
		for(int i=2;i<n;i++)
			sum+=count(n,i);
		int p=sum/GCD(sum,n-2);
		int q=(n-2)/GCD(sum,n-2);
		printf("%d/%d\n",p,q);
	}
	return 0;	
}


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值