codeforce - 13A A.Numbers
1 second
64 megabytes
standard input
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 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
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的更多相关文章
- codeforce 600A - Extract Numbers
学习string #include <bits/stdc++.h> #define eps 1e-8 #define M_PI 3.141592653589793 ; using name ...
- codeforce round#466(div.2)C. Phone Numbers
C. Phone Numbers time limit per test2 seconds memory limit per test256 megabytes inputstandard input ...
- Codeforce 9C - Hexadecimal's Numbers
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got ...
- codeforces 630C Lucky Numbers
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard i ...
- 解题报告:codeforce 7C Line
codeforce 7C C. Line time limit per test1 second memory limit per test256 megabytes A line on the pl ...
- Two progressions CodeForce 125D 思维题
An arithmetic progression is such a non-empty sequence of numbers where the difference between any t ...
- 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 ...
- 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 ...
- CodeForce 222C Reducing Fractions
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractio ...
随机推荐
- jupyter编辑快捷键
Jupyter笔记本有两种不同的键盘输入模式. 编辑模式允许您将代码或文本输入到一个单元格中,并通过一个绿色的单元格来表示 命令模式将键盘与笔记本级命令绑定在一起,并通过一个灰色的单元格边界显示,该边 ...
- IT修养-基础篇
1.科学基础 成为开发人员的过程不尽相同,有的是科班出身,有的是兴趣爱好,还有的是专业机构的培训,在这个过程中,可能全面或者零散甚至没有学习过计算机基础学科,但无论是哪一种,想要成为更高层次的开发人员 ...
- MySQL 相关规约(v1.0)
0)前言 a. 基本规约 [强制]表存储引擎必须使用InnoDB(针对主库一般是强制要求的) [强制]表字符集默认使用utf8,必要时候使用utf8mb4(个人踩坑:emoji表情存储问题) 说明: ...
- 23种设计模式之模板方法(Template Pattern)
定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤 AbstractClass:抽象类.用来定义算法骨架和原语操作,在这个类里 ...
- 使用servlet+jdbc+MD5实现用户加密登录
/** * 分析流程: * 1.前端页面提交登录请求 * 2.被web.xml拦截,进入到LoginServlet(有两种方式:方式一,在web.xml文件中配置servlet拦截器;方式二,不用在w ...
- cmd控制台 wrapper | OpenSCManager failed - 拒绝访问。 (0x5)解决
在windows上安装mycat执行命令时, D:\develop\Mycat\bin>mycat.bat install 返回wrapper | OpenSCManager failed - ...
- 58同城AES签名接口分析
背景:需要获取58同城上面发布的职位信息,其中的包括职位的招聘要求,薪资福利,公司的信息,招聘者的联系方式.(中级爬虫的难度系数) 职位详情页分析 某个职位详情页的链接 https://qy.m.58 ...
- spring5 源码深度解析----- Spring事务 是怎么通过AOP实现的?(100%理解Spring事务)
此篇文章需要有SpringAOP基础,知道AOP底层原理可以更好的理解Spring的事务处理. 自定义标签 对于Spring中事务功能的代码分析,我们首先从配置文件开始人手,在配置文件中有这样一个配置 ...
- C#常见的算法面试题
一.求以下表达式的值,写出您想到的一种或几种实现方法: 1-2+3-4+……+m //方法一,通过顺序规律写程序,同时也知道flag标志位的重要性. static int F1(int m) { in ...
- spring Bean的三种配置方式
Spring Bean有三种配置方式: 传统的XML配置方式 基于注解的配置 基于类的Java Config 添加spring的maven repository <dependency> ...