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
进制相关
5output
7/3input
3output
2/1NoteIn 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; }
相关文章推荐
- A. Super Agent
- A. Increasing Sequence
- A. Power Consumption Calculation
- 【问题解决】FragmentTabHost 底部菜单栏,切换Frgment时重新加载问题
- 使用Ajax实现异步用户名验证
- hiho#1139 : 二分·二分答案
- A. Die Roll
- 错排公式
- Crontab配置及使用总结
- Oracle内置表二
- CalendarView功能与用法(日历视图)
- 报名|「OneAPM x DaoCloud」技术公开课:Docker性能监控!
- Friday the Thirteenth
- DINIC 模板
- Greedy Gift Givers
- Activity之封装intent
- 2015年06月17日
- HDU 1215七夕节
- Codeforces Beta Round #8
- Codeforces Beta Round #7