大意: 给定$x,y$, 求第$x$小的最小素因子为$y$的数, 若答案>1e9输出0.

若$y>=60$, 可以暴力筛出1e9/60以内的答案.

否则容斥+二分算出答案.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, P2 = 998244353, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head const int M = 2e7+10, S = 60;
int x, y, cnt, ret;
bool vis[M];
int p[S]; int dfs(int d, int num, int z) {
return d>cnt?num*z:dfs(d+1,num,z)+dfs(d+1,num/p[d],-z);
} int main() {
scanf("%d%d", &x, &y);
if (x==1) return printf("%d\n", y),0;
if ((ll)y*y>1e9) return puts("0"),0;
if (y>=S) {
int n = 1e9/y, sum = 0;
REP(i,2,y-1) if (!vis[i]) {
for (int j=i;j<=n;j+=i) vis[j]=1;
}
REP(i,1,n) if (!vis[i]) {
if (++sum==x) return printf("%d\n",i*y),0;
}
return puts("0"),0;
}
REP(i,2,y-1) if (!vis[i]) {
p[++cnt] = i;
for (int j=2*i; j<y; j+=i) vis[j]=1;
}
int l=1, r=1e9/y, ans=0;
while (l<=r) {
if (dfs(1,mid,1)>=x) ans=mid,r=mid-1;
else l=mid+1;
}
printf("%d\n", ans*y);
}

最新文章

  1. Nacl开发
  2. 分享一个oraclehelper
  3. JavaScriptSerializer使用条件
  4. Socket之TCP连接_TcpNoDelay
  5. 版本控制--github相关
  6. Sharepoint学习笔记—习题系列--70-576习题解析 -(Q6-Q8)
  7. PHP KMP算法实现
  8. livewriter写Blog 神秘失踪?
  9. Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用
  10. 你可能没听过的 Java 8 中的 10 个特性
  11. SqlBulkCopy的一个例子
  12. ArcGIS制图表达Representation-规则和几何效果
  13. 基于 Maven 的多模块 Java ( Spring ) 项目构建
  14. 【接口测试】【SOAP】简单的接口测试学习
  15. .1-浅析webpack源码之webpack.cmd
  16. thinkphp 多对多关联模型(转)
  17. C++与Java混合编程
  18. CS231n课程笔记翻译1:Python Numpy教程
  19. Apache Hive (四)Hive的连接3种连接方式
  20. word的xml文件中空白页和换页

热门文章

  1. Tomcat7修改根路径应用
  2. 使用python播放音乐
  3. Resharper错误提示方法的命名
  4. java读取XML文件,及封装XML字符串
  5. 为macos开启外接显示器hdpi分辨率
  6. linux内核中的MFD子系统
  7. 质量保障&amp;&amp;质量体系建设
  8. coreDNS域名无法解析问题
  9. springboot-helloworld-eclipse
  10. CTF—攻防练习之Capture the Flag