http://acm.hdu.edu.cn/showproblem.php?pid=2031
http://codeforces.com/problemset/problem/13/A
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 contains one integer number A (3 ≤ A ≤ 1000).
Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator.
5
7/3
3
2/1
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <cmath>
using namespace std;
int getsum(int a,int t){
int ans=0;
while(a){
ans+=a%t;
a/=t;
}
return ans;
}
int gcd(int a,int b){
while(b){
int t=a%b;
a=b;
b=t;
}
return a;
}
int main(){
int n;
int ans=0;
while(cin>>n){
ans=0;
for(int i=2;i<=n-1;i++)
ans+=getsum(n,i);
int tb=n-2;
int tt=gcd(ans,tb);
cout<<ans/tt<<'/'<<tb/tt<<endl;
}
return 0;
}
二
7 2 23 12 -4 3
111 1B -11#include <stdio.h> void jinzhi(int x,int y) { if(x) { jinzhi(x/y,y); printf("%c",x%y>9 ? x%y-10+'A':x%y+'0'); } } int main() { int x,y; void jinzhi(int x,int y); while(~scanf("%d%d",&x,&y)) { if(x>0) jinzhi(x,y); else if(x<0) { putchar('-'); jinzhi(-x,y); } else printf('0'); putchar('\n'); } return 0; }