BJFU fudq的等式
/*
BJFU fudq的等式
http://101.200.220.237/contest/19/problem/118/
数论 勒让德定理 二分答案
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
//#define test
using namespace std;
const int Nmax=;
const long long INF=100000000000005LL;
long long p[Nmax];
long long times[Nmax];
int cnt;
long long n,x,y; long long Legendre(long long n,long long p,long long y)
{
long long ans=0LL;
while(n>)
{
ans+=n/p;
if(ans>y)
return y+1LL;
n/=p;
}
return ans;
} int is(long long n)
{
for(int i=;i<=cnt;i++)
{
if(Legendre(n,p[i],times[i]*y)<times[i]*y)
return ;
}
return ;
}
long long get()
{
long long n=0LL;
long long l=1LL,r=INF;
while(l<r)
{
long long mid=(l+r)>>;
long long m=is(mid);
//printf("l:%lld r:%lld mid:%lld x:%lld y:%lld num:%lld\n",l,r,mid,x,y,m);
if(!m)
l=mid+;
else
r=mid-;
}
if(n==0LL && !is(r))
n=r+;
else if(n==0LL && is(r))
n=r;
return n; }
//long long get()
//{
//long long m=-1LL;
//for(int i=1;i<=cnt;i++)
//{
//m=max(m,get(p[i],times[i]*y));
//}
//return m;
//}
int main()
{
#ifdef test
#endif
//freopen("test.in","r",stdin);
while(scanf("%lld%lld",&x,&y)==)
{
cnt=;
for(int i=;i*i<=x;i++)
{
if(x%i==)
{
p[++cnt]=i;
times[cnt]=;
while(x%i==)
{
x/=i;
times[cnt]++;
}
}
}
if(x!=)
{
p[++cnt]=x;
times[cnt]=;
} if(cnt==)
{
//printf("error\n");
printf("0\n");
continue;
}
printf("%lld\n",get());
}
return ;
}
BJFU fudq的等式的更多相关文章
- BJFU 1440 fudq的ACM
矩阵快速幂 #include<cstdio> #include<algorithm> using namespace std; ; const int INF =1e9; ; ...
- NOIP200806 火柴棒等式【B005】
[B005]火柴棒等式[难度B]———————————————————————————————————————————————————————————— [题目要求] 给你n根火柴棍,你可以拼出多少个 ...
- BZOJ2118墨墨的等式[数论 最短路建模]
2118: 墨墨的等式 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1317 Solved: 504[Submit][Status][Discus ...
- 【bzoj2118】 墨墨的等式
http://www.lydsy.com/JudgeOnline/problem.php?id=2118 (题目链接) 题意 给出${B}$的取值范围${[Bmin,Bmax]}$,求方程${a_{1 ...
- Bzoj2118 墨墨的等式
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1488 Solved: 578 Description 墨墨突然对等式很感兴趣,他正在研究a1x1+ ...
- NOIP2008提高组火柴棒等式(模拟)——yhx
题目描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0-9的拼法如图所示: 注意: 加号与等号各自 ...
- 数论+spfa算法 bzoj 2118 墨墨的等式
2118: 墨墨的等式 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1283 Solved: 496 Description 墨墨突然对等式很感兴 ...
- TYVJ P1012 火柴棒等式 Label:枚举
背景 NOIP2008年提高组第二题 描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0-9的拼法 ...
- noip2008 火柴棒等式
P1149 火柴棒等式 1.9K通过 3.7K提交 题目提供者该用户不存在 标签搜索/枚举模拟2008NOIp提高组 难度普及- 提交该题 讨论 题解 记录 题目描述 给你n根火柴棍,你可以拼出多 ...
随机推荐
- 【剑指offer】Q19:二叉树的镜像
def MirroRecursively(root): # root is None or just one node, return root if None == root or None == ...
- 实战Java内存泄漏问题分析 -- hazelcast2.0.3使用时内存泄漏 -- 2
hazelcast 提供了3中方法调用startCleanup: 第一种是在ConcuurentMapManager的构造函数中,通过调用node的executorManager中的Scheduled ...
- cmd执行调用打开文件
Process p = new Process();//新进程 p.StartInfo.FileName = "cmd.exe";//打开cmd程序 p.StartInfo.Use ...
- luogu3799 妖梦拼木棒
题目大意 有n根木棒,现在从中选4根,想要组成一个正三角形,问有几种选法?木棒长度都<=5000. 题解 根据容斥原理,三角形两条边分别由长度相等的单根木棒组成,另一条边由两条小于该边长的木棒构 ...
- Truck History --hdoj
Truck History Time Limit : 4000/2000ms (Java/Other) Memory Limit : 131072/65536K (Java/Other) Tota ...
- 【POJ 3696】 The Luckiest number
[题目链接] http://poj.org/problem?id=3696 [算法] 设需要x个8 那么,这个数可以表示为 : 8(10^x - 1) / 9, 由题, L | 8(10^x - 1) ...
- Python基础:lambda 匿名函数
格式 lambda argument1, argument2,... argumentN : expression square = lambda x: x**2 print(square(2)) 与 ...
- Blender Python UV 学习
Blender Python UV 学习 1. bmesh面转换 bm = bmesh.from_edit_mesh(bpy.context.edit_object.data) bm.faces.en ...
- python基本数据类型之列表list
list的基本功能 结果类型 中括号括起来 逗号(,)分割每一个元素 列表中的元素可以是数字,字符串,列表,布尔值所有的都能放 索引,切片 ? 1 2 3 li = [1, 3, 5, " ...
- C# How to convert MessageBodyStream to MemoryStream?
通过WCF服务从数据库取文档数据时,返回的是Stream对象,在DevExpress的PDFViewer显示时,用PDFViewer.LoadDocunent(Stream stream);方法时,报 ...