hdu1099
#include<iostream>
using namespace std;
__int64 gcd(__int64 a,__int64 b)
{
return b?gcd(b,a%b):a;
}
__int64 lcm(__int64 a,__int64 b)
{
return a/gcd(a,b)*b;
}
int numlen(__int64 n)
{
int len=0;
while(n)
{
n/=10;
len++;
}
return len;
}
int main()
{
__int64 s,m,g,d;
int l1,l2,i,n;
while(scanf("%I64d",&n)==1)
{
m=1; //分母
s=0; //分子
for(i=1;i<=n;i++)
m=lcm(m,i);
for(i=1;i<=n;i++)
s+=m/i;
s*=n;
g=gcd(m,s); //求最大公约数
s/=g;
m/=g;
d=s/m; //整数部分
s%=m;
if(s==0)
{
printf("%d\n",d);
continue;
}
l1=numlen(d);
l2=numlen(m);
for(i=0;i<=l1;i++)
putchar(' ');
printf("%I64d\n",s);
printf("%I64d ",d);
for(i=1;i<=l2;i++)
putchar('-');
putchar('\n');
for(i=0;i<=l1;i++)
putchar(' ');
printf("%I64d\n",m);
}
return 0;
}
hdu1099的更多相关文章
随机推荐
- android OTG【转】
本文转载自:http://blog.csdn.net/xubin341719/article/details/7707056 一.OTG的概念 OTG是On-The-Go的缩写,是近年发展起来的技术, ...
- java:eclipse4.4 安装tomcat插件
一.Eclipse 4.4下载地址:http://www.eclipse.org/downloads/ (Eclipse官网).Eclipse4.4版本默认已经集成了Ant和Maven插件,这点挺不错 ...
- java:Properties属性文件概念
java:Properties属性文件概念 在java之前的国际化程序中提出了一个属性文件的概念,属性文件的后缀是:*.properties,那么在java中提供了意个属性文件的专门操作类,Prope ...
- gethub的安装
下载地址: windows的下载地址 https://gitforwindows.org/ 一.安装 win下的安装注意要点: 1.环境变量 2.文件结束符如何处理(windows下/r/n,linu ...
- 动态规划 两个字符串之间的编辑距离 leetcode72
public static int minDistance(String word1, String word2) { char[] s1 = word1.toCharArray(); char[] ...
- linux命令学习笔记(3):pwd命令
Linux中用 pwd 命令来查看”当前工作目录“的完整路径. 简单得说,每当你在终端进行操作时, 你都会有一个当前工作目录. 在不太确定当前位置时,就会使用pwd来判定当前目录在文件系统内的确切位置 ...
- linux命令学习笔记(12):more命令
more命令,功能类似 cat ,cat命令是整个文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便 使用者逐页阅读,而最基本的指令就是按空白键(space)就往下一页显示,按 b 键就 ...
- LeetCode Majority Element I
原题链接在这里:https://leetcode.com/problems/majority-element/ 题目: Given an array of size n, find the major ...
- 洛谷 P4525 & P4526 [模板] 自适应辛普森积分
题目:https://www.luogu.org/problemnew/show/P4525 https://www.luogu.org/problemnew/show/P4526 学习辛普森积分:h ...
- bzoj 2535 & bzoj 2109 航空管制 —— 贪心+拓扑序
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2535 https://www.lydsy.com/JudgeOnline/problem.p ...