牛客 40E 珂朵莉的数论题
2024-09-05 09:34:34
大意: 给定$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);
}
最新文章
- Nacl开发
- 分享一个oraclehelper
- JavaScriptSerializer使用条件
- Socket之TCP连接_TcpNoDelay
- 版本控制--github相关
- Sharepoint学习笔记—习题系列--70-576习题解析 -(Q6-Q8)
- PHP KMP算法实现
- livewriter写Blog 神秘失踪?
- Struts标签、Ognl表达式、el表达式、jstl标签库这四者之间的关系和各自作用
- 你可能没听过的 Java 8 中的 10 个特性
- SqlBulkCopy的一个例子
- ArcGIS制图表达Representation-规则和几何效果
- 基于 Maven 的多模块 Java ( Spring ) 项目构建
- 【接口测试】【SOAP】简单的接口测试学习
- .1-浅析webpack源码之webpack.cmd
- thinkphp 多对多关联模型(转)
- C++与Java混合编程
- CS231n课程笔记翻译1:Python Numpy教程
- Apache Hive (四)Hive的连接3种连接方式
- word的xml文件中空白页和换页