A. Numbers
time limit per test

1 second

memory limit per test

64 megabytes

input

standard input

output

standard output

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 test(s)
input
5
output
7/3
input
3
output
2/1
Note

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 "stdio.h"
#include "string.h"
#include "stdlib.h" int n;
int ntable[1000] ;
int su(int d,int n)
{int i=0,sum=0;
int r[1000];memset(r,0,100);
int tmp;
int l;
while(d!=0)
{tmp=d%n;
r[i]=ntable[tmp];
i++;
d/=n;
}
l=i;
for(i=0;i<l/2;i++)
{tmp=r[i];
r[i]=r[l-i-1];
r[l-i-1]=tmp;
}
for(i=0;i<l;i++)
sum+=r[i];
return sum;
} int gcd(int a,int b){
int r;
while(b>0){
r=a%b;
a=b;
b=r;
}
return a;
} int main( )
{
int a,i=0,ans,fm=0;
for(i=0;i<1000;i++)
{
*(ntable+i)=i;
}
while(~ scanf( "%d",&a ))
{
fm=a-1;ans=0;
for(i=2;i<=fm;i++)
{
ans+=su(a,i) ;
}
printf( "%d/%d\n",ans/gcd(ans,fm-1),(fm-1)/gcd(ans,fm-1) );
}
return 0;
}

codeforce - 13A A.Numbers的更多相关文章

  1. codeforce 600A - Extract Numbers

    学习string #include <bits/stdc++.h> #define eps 1e-8 #define M_PI 3.141592653589793 ; using name ...

  2. codeforce round#466(div.2)C. Phone Numbers

    C. Phone Numbers time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...

  3. Codeforce 9C - Hexadecimal's Numbers

    One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ...

  4. codeforces 630C Lucky Numbers

    C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...

  5. 解题报告:codeforce 7C Line

    codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...

  6. Two progressions CodeForce 125D 思维题

    An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...

  7. CodeForce 577B Modulo Sum

    You are given a sequence of numbers a1, a2, ..., an, and a number m. Check if it is possible to choo ...

  8. CodeForce 176C Playing with Superglue

    Two players play a game. The game is played on a rectangular board with n × m squares. At the beginn ...

  9. CodeForce 222C Reducing Fractions

    To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractio ...

随机推荐

  1. 更改hadoop集群yarn的webui中的开始时间和结束时间为本地时间

    yarn集群的webui地址为:http://rm:8088 执行任务后,任务的开始时间和结束时间都是utc时间,查看很不方便. 查找相关资料发现hadoop有补丁包,补丁地址:https://iss ...

  2. alpha测试和beta测试的区别

    alpha测试版,有点相当于内部测试,一般开发人员在场   ,是由用户做测试,但开发人员在场,一般是请用户到开发现场去测试  beta测试版,完全交给用户,由用户做测试,返回测试报告,相当于发行前的一 ...

  3. Dubbo学习系列之十三(Mycat数据库代理)

    软件界有只猫,不用我说,各位看官肯定知道是哪只,那就是大名鼎鼎的Tomcat,现在又来了一只猫,据说是位东方萌妹子,暂且认作Tom猫的表妹,本来叫OpencloudDB,后又改名为Mycat,或许Ca ...

  4. thymeleaf 遍历使用案例

    1.语法: th:each属性用于迭代循环,语法:th:each="obj,iterStat:${objList}" 迭代对象可以是List,Map,数组等; 2.说明:iterS ...

  5. ZK集群的Leader选举源码阅读

    前言 ZooKeeper对Zab协议的实现有自己的主备模型,即Leader和learner(Observer + Follower),有如下几种情况需要进行领导者的选举工作 情形1: 集群在启动的过程 ...

  6. 一条SQL查询语句是如何执行的?

    本篇文章将通过一条 SQL 的执行过程来介绍 MySQL 的基础架构. 首先有一个 user_info 表,表里有一个 id 字段,执行下面这条查询语句: select * from user_inf ...

  7. LitePal的存储操作

    传统的存储数据方式   其实最传统的存储数据方式肯定是通过SQL语句拼接字符串来进行存储的,不过这种方式有点过于“传统”了,今天我们在这里就不讨论这种情况.实际上,Android专门提供了一种用于存储 ...

  8. springboot结合jpa

    idea中新建springboot项目,引入spring-boot-starter-data-jpa依赖 application.yml中配置数据库连接,示例如下: spring: datasourc ...

  9. spring和springmvc的基础知识点

    1.spring中使用@Service("userservice")如何在其他地方引用这个service? (1)getBean("userservice") ...

  10. e课表项目第二次冲刺周期第三天

    昨天干了什么? 昨天和我们组的组员商量,确定了第二个界面的框架内容,即内容的输入和完成按钮,然后通过在网上搜索图片资源,然后我们利用ps软件,将图片通通设置了大小,进行了裁剪,最后为我们所利用,实现第 ...