您的位置:首页 > 其它

A. Numbers

2016-04-21 19:02 288 查看
A. Numberstime limit per test1 secondmemory limit per test64 megabytesinputstandard inputoutputstandard outputLittle 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.InputInput contains one integer number A (3?≤?A?≤?1000).OutputOutput 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
NoteIn 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.

进制相关
/* ***********************************************
Author        :
Created Time  :2015/6/8 19:15:10
File Name     :5.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 1<<30
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << 61;
const double eps=1e-5;
using namespace std;

bool cmp(int a,int b){
return a>b;
}
int gcd(int a,int b){
return a==0?b:gcd(b%a,a);
}
int main()
{
#ifndef ONLINE_JUDGE
//freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int a,sum;
while(cin>>a){
sum=0;
for(int i=2;i<a;i++){
int t=a;
while(t>0){
sum+=(t%i);
t=t/i;
}
}
int k=gcd(a-2,sum);
printf("%d/%d\n",sum/k,(a-2)/k);

}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: