Educational Codeforces Round 37 (Rated for Div. 2) G
5 seconds
256 megabytes
standard input
standard output
Let's denote as L(x, p) an infinite sequence of integers y such that gcd(p, y) = 1 and y > x (where gcd is the greatest common divisor of two integer numbers), sorted in ascending order. The elements of L(x, p) are 1-indexed; for example, 9, 13 and 15 are the first, the second and the third elements of L(7, 22), respectively.
You have to process t queries. Each query is denoted by three integers x, p and k, and the answer to this query is k-th element of L(x, p).
The first line contains one integer t (1 ≤ t ≤ 30000) — the number of queries to process.
Then t lines follow. i-th line contains three integers x, p and k for i-th query (1 ≤ x, p, k ≤ 106).
Print t integers, where i-th integer is the answer to i-th query.
3
7 22 1
7 22 2
7 22 3
9
13
15
5
42 42 42
43 43 43
44 44 44
45 45 45
46 46 46
187
87
139
128
141 题意 q个询问 大于x,第k个与p互质的数
解析 对于一个数 mid 我们可以容斥算出1-mid 与 p互质的数有多少,所以二分答案就可以了。
AC代码
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e4+;
const ll mod=;
ll yinzi[maxn],cnt;
void euler(ll n)
{
cnt=;
ll a=n;
for(ll i=; i*i<=a; i++)
{
if(a%i==)
{
yinzi[cnt++]=i;
while(a%i==)
a/=i;
}
}
if(a>)
yinzi[cnt++]=a;
}
ll solve(ll n)
{
ll ans=;
for(ll i=; i<(<<cnt); i++)
{
ll temp=,jishu=;
for(ll j=; j<cnt; j++)
{
if(i&(<<j))
temp=temp*yinzi[j],jishu++;
}
if(jishu==)
continue;
if(jishu&)
ans+=n/temp;
else
ans-=n/temp;
}
return ans;
}
int main()
{
ll t,n,m,k;
scanf("%lld",&t);
while(t--)
{
scanf("%lld%lld%lld",&m,&n,&k);
euler(n);
ll ans1=m-solve(m);
ll l=m+,r=1e7;
while(l<=r)
{
ll mid=(l+r)/;
ll cur=mid-solve(mid)-ans1;
if(cur<k)
l=mid+;
else
r=mid-;
}
printf("%lld\n",r+);
}
}
Educational Codeforces Round 37 (Rated for Div. 2) G的更多相关文章
- Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements (思维,前缀和)
Educational Codeforces Round 37 (Rated for Div. 2)C. Swap Adjacent Elements time limit per test 1 se ...
- Educational Codeforces Round 39 (Rated for Div. 2) G
Educational Codeforces Round 39 (Rated for Div. 2) G 题意: 给一个序列\(a_i(1 <= a_i <= 10^{9}),2 < ...
- Educational Codeforces Round 37 (Rated for Div. 2) 920E E. Connected Components?
题 OvO http://codeforces.com/contest/920/problem/E 解 模拟一遍…… 1.首先把所有数放到一个集合 s 中,并创建一个队列 que 2.然后每次随便取一 ...
- Educational Codeforces Round 37 (Rated for Div. 2)
我的代码应该不会被hack,立个flag A. Water The Garden time limit per test 1 second memory limit per test 256 mega ...
- [Codeforces]Educational Codeforces Round 37 (Rated for Div. 2)
Water The Garden #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h ...
- Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 图论
E. Connected Components? You are given an undirected graph consisting of n vertices and edges. Inste ...
- Educational Codeforces Round 58 (Rated for Div. 2) G 线性基
https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...
- Educational Codeforces Round 53 (Rated for Div. 2)G. Yet Another LCP Problem
题意:给串s,每次询问k个数a,l个数b,问a和b作为后缀的lcp的综合 题解:和bzoj3879类似,反向sam日神仙...lcp就是fail树上的lca.把点抠出来建虚树,然后在上面dp即可.(感 ...
- Educational Codeforces Round 51 (Rated for Div. 2) G. Distinctification(线段树合并 + 并查集)
题意 给出一个长度为 \(n\) 序列 , 每个位置有 \(a_i , b_i\) 两个参数 , \(b_i\) 互不相同 ,你可以进行任意次如下的两种操作 : 若存在 \(j \not = i\) ...
随机推荐
- IOS访问webserver接口
接口调用参数只能是字符串格式,返回格式支持3种(字符串,数组,DataSet) 需要引用第三方库,包含(DataSet,PlatServinceDataParser,WebserviceCommon, ...
- COGS 74. [NOIP2006] 明明的随机数 (Splay小练习。。)
☆ 输入文件:random.in 输出文件:random.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述] 明明想在学校中请一些同学一起做一项问卷调查,为了 ...
- http响应头状态描述
状态代码有三位数字组成,第一个数字定义了响应的类别,且有五种可能取值:1xx:指示信息--表示请求已接收,继续处理2xx:成功--表示请求已被成功接收.理解.接受3xx:重定向--要完成请求必须进行更 ...
- html5shiv.js让吃屎的IE6、IE7、IE8支持html5去吧
插件介绍 用于解决IE9以下版本浏览器对HTML5新增标签不识别,并导致CSS不起作用的问题.所以我们在使用过程中,想要让低版本的浏览器,即IE9以下的浏览器支持,那么这款html5shiv.js是一 ...
- docker 搭建 Java Web 运行环境
安装环境:jdk,tomcat,mysql,nginx
- docker环境安装
centos7安装docker环境 # step 1: 安装必要的一些系统工具 yum install -y yum-utils device-mapper-persistent-data lvm2 ...
- Xgboost集成算法
集成算法思想: Xgboost基本原理: Xboost中是一个树(函数)接着一个树(函数)往里加,每加一个树都希望整体表达效果更好一些,即:目标函数逐步减小. 每加入一个函数,使目标函数逐渐减小,整体 ...
- DLL动态链接库的创建
dll的创建主要有两种方法:一是使用 __declspec(dllexport) 创建dll,二是使用模块定义(.def)文件创建dll. 使用 __declspec(dllexport) 创建dll ...
- 【搜索】P1032 字串变换
题目描述 已知有两个字串A,B及一组字串变换的规则(至多6个规则): A1 ->B1 A2 -> B2 规则的含义为:在 A中的子串 A1 可以变换为B1,A2 可以变换为 ...
- 牛客网数据库SQL实战 1-11
1. 查找最晚入职员工的所有信息 CREATE TABLE `employees` ( `emp_no` ) NOT NULL, `birth_date` date NOT NULL, `first_ ...