#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的更多相关文章

随机推荐

  1. JsonSchema使用详解

    JSON Schema是一个用于验证JSON数据结构的强大工具, 我查看并学习了JSON Schema的官方文档, 做了详细的记录, 分享一下. 我们可以使用JSON Schema在后续做接口测试中做 ...

  2. svn及git使用笔记

    这周发生好几件大事: 谷歌发布SHA-1安全加密碰撞实例 Cloudflare 泄露网络会话中的加密数据 linux内核漏洞 CVE-2017-6074 加密在网络中越来越受关注,目前github的提 ...

  3. Hadoop切换namenode为active

    hadoop切换namenode为active 进入hadoop/bin目录下 ./yarn rmadmin -transitionToActive --forcemanual rm1 重新启动zkf ...

  4. 格式化namenode时 报错 No Route to Host from node1/192.168.1.111 to node3:8485 failed on socket timeout exception: java.net.NoRouteToHostException: No route to host

    // :: FATAL namenode.NameNode: Failed to start namenode. org.apache.hadoop.hdfs.qjournal.client.Quor ...

  5. Quota Management and Enforcement

    Neutron API中大多的resource都需要quota limits. Neutron API暴露出一个extension 来管理quota,Quota limits are enforced ...

  6. for循环中删除map中的元素,valgrind检测提示error:Invalid read of size 8

    #include <iostream> #include <map> using namespace std; class A { public: typedef std::m ...

  7. python习题-替换敏感词

    #3.有一个文件,里面有一些敏感词汇,如下,如果输入这些词,就用**代替,#然后输出,例如输入今天没吃饭,碰到一个傻逼,原来那个sb是小明.输出今天没吃饭,碰到一个**,原来那个**是小明.#需求分析 ...

  8. html中Meta属性

    <!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...

  9. 机器学习 Support Vector Machines 2

    优化的边界分类器 上一讲里我们介绍了函数边界和几何边界的概念,给定一组训练样本,如果能够找到一条决策边界,能够使得几何边界尽可能地大,这将使分类器可以很可靠地预测训练样本,特别地,这可以让分类器用一个 ...

  10. 倍增模板orz

    #include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #i ...