/*
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的等式的更多相关文章

  1. BJFU 1440 fudq的ACM

    矩阵快速幂 #include<cstdio> #include<algorithm> using namespace std; ; const int INF =1e9; ; ...

  2. NOIP200806 火柴棒等式【B005】

    [B005]火柴棒等式[难度B]———————————————————————————————————————————————————————————— [题目要求] 给你n根火柴棍,你可以拼出多少个 ...

  3. BZOJ2118墨墨的等式[数论 最短路建模]

    2118: 墨墨的等式 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1317  Solved: 504[Submit][Status][Discus ...

  4. 【bzoj2118】 墨墨的等式

    http://www.lydsy.com/JudgeOnline/problem.php?id=2118 (题目链接) 题意 给出${B}$的取值范围${[Bmin,Bmax]}$,求方程${a_{1 ...

  5. Bzoj2118 墨墨的等式

    Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1488  Solved: 578 Description 墨墨突然对等式很感兴趣,他正在研究a1x1+ ...

  6. NOIP2008提高组火柴棒等式(模拟)——yhx

    题目描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0-9的拼法如图所示: 注意: 加号与等号各自 ...

  7. 数论+spfa算法 bzoj 2118 墨墨的等式

    2118: 墨墨的等式 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 1283  Solved: 496 Description 墨墨突然对等式很感兴 ...

  8. TYVJ P1012 火柴棒等式 Label:枚举

    背景 NOIP2008年提高组第二题 描述 给你n根火柴棍,你可以拼出多少个形如“A+B=C”的等式?等式中的A.B.C是用火柴棍拼出的整数(若该数非零,则最高位不能是0).用火柴棍拼数字0-9的拼法 ...

  9. noip2008 火柴棒等式

    P1149 火柴棒等式 1.9K通过 3.7K提交 题目提供者该用户不存在 标签搜索/枚举模拟2008NOIp提高组 难度普及- 提交该题 讨论 题解 记录   题目描述 给你n根火柴棍,你可以拼出多 ...

随机推荐

  1. Eclipseproject出现红叉

    通过import导入包的时候往往会出现红叉的情况.但又没有错:这样的情况能够这样解决 1.选中项目.按Alt键和Enter键 2.选Andriod,在右側的版本号信息里选择一个不同的版本号,如原来默认 ...

  2. VS2013 EF6连接MySql

    1.安装mysql server下载地址 http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21-winx64.zip 2.安装MySql的VS插件 ...

  3. 安卓离线SDK Windows版 资源包下载地址全集

    1.Tools    https://dl-ssl.google.com/android/repository/platform-tools_r19.0.1-windows.zip https://d ...

  4. luogu1168 中位数

    题目大意 给出一个长度为N的非负整数序列A[i],对于所有1 ≤ k ≤ (N + 1) / 2,输出A[1], A[3], -, A[2k - 1]的中位数.即前1,3,5,--个数的中位数. 题解 ...

  5. POJ1742 Coins 背包

    题目大意:给出一些钱币的价值和对应的数目,求在一定价值限定下这些钱币能凑成的价值数. 本题用多重背包直接拆分或二进制拆分法都太慢.说起处理一组物品,完全背包可算是比较效率高的,但是本题中物体的数目是有 ...

  6. bzoj4887: [Tjoi2017]可乐

    一眼暴力宽搜(最近比赛想暴力想疯了... 很明显的矩乘,然后自爆可以看作走向向一个无出边的点 然后没啥难的了吧. #include<cstdio> #include<iostream ...

  7. 院校-国外-美国:斯坦福大学( Stanford)

    ylbtech-院校-国外-美国:斯坦福大学( Stanford) 斯坦福大学(Stanford University),全名小利兰·斯坦福大学(Leland Stanford Junior Univ ...

  8. 南海区行政审批管理系统接口规范v0.3(规划) 3.业务办理API 3.1.businessAuditById【业务办理】

    {"c_accept":"Q2015112400002","c_operators":"gz99","v_op ...

  9. Gym-101915A Printing Books 模拟

    题面 题意:给你N,X,   X表示这本书从X开始编号,每个X是几位数,计数器就加几, 然后问你如果从X,开始编号,计数器为N的时候,翻了几页,不能刚好为N输出-1. (例如,5 99,答案为2,因为 ...

  10. c语言递归讲解分析

    C语言允许函数调用它自己,这种调用的过程称为"递归(recursion)" 举例说明,如下代码: #include <stdio.h> void up_and_down ...