51 nod 1189 阶乘分数
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1189
题目思路:
1/n! = 1/x +1/y
==> n! * (x + y) = x * y(右边通分。然后转化)
==> n!^2 = (x - n!)*(y - n!)(左右两边加上n方)
==> a = b * c ,a = n!^2 ,b = x - n! ,c = y - n!
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long LL;
const int mod = 1e9+7;
const int maxn=1e6+5;
bool prime[maxn];
int p[maxn/10];
int k;
void isprime()
{
k=0;
LL i,j;
memset(prime, true, sizeof(prime));
for(i=2; i<maxn; i++)
{
if(prime[i])
{
p[k++]=i;
for(j=i*i; j<maxn; j+=i)
prime[j]=false;
}
}
/*for(int i=0; i<10; i++)
cout<<p[i]<<" ";*/
}
LL get(LL m, LL p)
{
if(m<p)
return 0;
return m/p+get(m/p,p);
}
LL quickmod(LL a, LL b)
{
LL ans = 1;
while(b)
{
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans ;
}
int main()
{
isprime();
int n;
while(~scanf("%d",&n))
{
LL ans=1;
LL m = quickmod(2,(LL)mod-2);
for(int i=0; i<k&&p[i]<=n; i++)
{
LL tmp = (get(n,p[i])*2+1)%mod;
ans=ans*tmp%mod;
}
ans = ans*m%mod;
ans = (ans+m%mod)%mod;
printf("%lld\n",ans);
}
return 0;
}
51 nod 1189 阶乘分数的更多相关文章
- 51nod1189 阶乘分数
(x-n!)(y-n!)=n!2 ans=t[n]+1.t表示的是n!2的小于n!的约数个数.n!2=p1a1*p2a2*p3a3...t[n]=(a1+1)*(a2+1)...-1 /2; 2对于n ...
- 51 nod 1439 互质对(Moblus容斥)
1439 互质对 题目来源: CodeForces 基准时间限制:2 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 有n个数字,a[1],a[2],…,a[n].有一个集合,刚开 ...
- 51 nod 1495 中国好区间
1495 中国好区间 基准时间限制:0.7 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 阿尔法在玩一个游戏,阿尔法给出了一个长度为n的序列,他认为,一段好的区间,它的长度是& ...
- 51 nod 1427 文明 (并查集 + 树的直径)
1427 文明 题目来源: CodeForces 基准时间限制:1.5 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 安德鲁在玩一个叫“文明”的游戏.大妈正在帮助他. 这个游 ...
- 51 nod 1055 最长等差数列(dp)
1055 最长等差数列 基准时间限制:2 秒 空间限制:262144 KB 分值: 80 难度:5级算法题 N个不同的正整数,找出由这些数组成的最长的等差数列. 例如:1 3 5 6 8 9 ...
- 51 nod 1421 最大MOD值
1421 最大MOD值 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 有一个a数组,里面有n个整数.现在要从中找到两个数字(可以 ...
- 51 nod 1681 公共祖先 (主席树+dfs序)
1681 公共祖先 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 难度:5级算法题 有一个庞大的家族,共n人.已知这n个人的祖辈关系正好形成树形结构(即父亲向儿子连边). 在另 ...
- 51 nod 1766 树上的最远点对(线段树+lca)
1766 树上的最远点对 基准时间限制:3 秒 空间限制:524288 KB 分值: 80 难度:5级算法题 n个点被n-1条边连接成了一颗树,给出a~b和c~d两个区间,表示点的标号请你求出两个 ...
- 51 nod 1405 树的距离之和
1405 树的距离之和 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 给定一棵无根树,假设它有n个节点,节点编号从1到n, 求任意两点之间的距离(最短路径)之 ...
随机推荐
- style="background-image: url(__HOMEPAGE__/views/IMJ2V2/images/banner2.jpg)"
style="background-image: url(__HOMEPAGE__/views/IMJ2V2/images/banner2.jpg)" 一.问题 backgroun ...
- 【Linux】JDK+Eclipse 搭建C/C++开发环境
注:本文所提供的参考示例是在CentOS Linux环境下的安装,不保证适用于其他版本的Linux系统. · 安装前的注意事项 编译源代码是需要对应的代码编译工具的,本文中安装的Eclipse只 ...
- Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制)
Android 仿QQ首页的消息和电话的切换,首页的头部(完全用布局控制) 首先贴上七个控制布局代码 1.title_text_sel.xml 字体颜色的切换 放到color文件夹下面 <?xm ...
- 分享关于浏览器对象 history对象
window.history.forward() == window.history.go(-1) //返回下一页 window.history.back() == window.history.go ...
- 推荐的JavaScript编码规范
http://www.qdfuns.com/notes/26812/7825414125719306fa409c709ee7b2a3.html
- XML获取节点信息值
XmlDocument doc = new XmlDocument(); doc.LoadXml(sreturn); XmlNode xNode = doc.SelectSingleNode(&quo ...
- 做raid1 经验总结
背景: MHP 3楼一台ThinkServer TS200 老服务器做RAID1,硬盘为: 2块3T RAID 设定里显示: 制作RAID1 只有700G多点可做. 系统安装: 可以正常在700G ...
- Android布局之RelativeLayout
RelativeLayout用到的一些重要的属性: 第一类:属性值为true或falseandroid:layout_centerHrizontal 水平居中android:layout_center ...
- C# Arcgis Engine 捕捉功能实现
namespace 捕捉 { public partial class Form1 : Form { private bool bCreateElement=true; ; ; private IEl ...
- Pku3664
<span style="color:#6600cc;">/* D - Election Time Time Limit:1000MS Memory Limit:655 ...