G. List Of Integers
time limit per test

5 seconds

memory limit per test

256 megabytes

input

standard input

output

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 xp and k, and the answer to this query is k-th element of L(x, p).

Input

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 xp and k for i-th query (1 ≤ x, p, k ≤ 106).

Output

Print t integers, where i-th integer is the answer to i-th query.

Examples
input
37 22 17 22 27 22 3

output
91315

input
542 42 4243 43 4344 44 4445 45 4546 46 46

output
18787139128141

题意 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+10;
const ll mod=1000000007;
ll yinzi[maxn],cnt;
void euler(ll n)
{cnt=0;ll a=n;for(ll i=2; i*i<=a; i++){if(a%i==0){yinzi[cnt++]=i;while(a%i==0)a/=i;}}if(a>1)yinzi[cnt++]=a;
}
ll solve(ll n)
{ll ans=0;for(ll i=0; i<(1<<cnt); i++){ll temp=1,jishu=0;for(ll j=0; j<cnt; j++){if(i&(1<<j))temp=temp*yinzi[j],jishu++;}if(jishu==0)continue;if(jishu&1)ans+=n/temp;elseans-=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+1,r=1e7;while(l<=r){ll mid=(l+r)/2;ll cur=mid-solve(mid)-ans1;if(cur<k)l=mid+1;elser=mid-1;}printf("%lld\n",r+1);}
}

转载于:https://www.cnblogs.com/stranger-/p/9811509.html

Educational Codeforces Round 37 (Rated for Div. 2) G相关推荐

  1. Educational Codeforces Round 37 (Rated for Div. 2) 1

    Educational Codeforces Round 37 (Rated for Div. 2) A.Water The Garden 题意:Max想给花园浇水.花园可被视为长度为n的花园床,花园 ...

  2. Educational Codeforces Round 37 (Rated for Div. 2) E. Connected Components? 暴力 + 补图的遍历

    传送门 文章目录 题意: 思路: 题意: n≤2e5,m≤2e5n\le2e5,m\le2e5n≤2e5,m≤2e5. 思路: 这是题是我上个题的一部分,算是个小知识点,暴力能过. 直接维护一个set ...

  3. 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 ...

  4. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  5. Educational Codeforces Round 126 (Rated for Div. 2)(A-E)

    A-Array Balancing 题意:给定两个数组a,b,a数组第i个数可以和b数组的第i个数交换,最终求 a1−a2|+|a2−a3|+⋯+|an−1−an||a1−a2|+|a2−a3|+⋯+ ...

  6. Educational Codeforces Round 138 (Rated for Div. 2) D

    Educational Codeforces Round 138 (Rated for Div. 2) D. Counting Arrays 题意 给定长度为nnn的数组aaa,若gcd(ai,i)= ...

  7. Educational Codeforces Round 114 (Rated for Div. 2) (A ~ F)全题解

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Educational Codeforces Round 114 (Rated for Div. 2) ...

  8. Educational Codeforces Round 106 (Rated for Div. 2)(A ~ E)题解(每日训练 Day.16 )

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 Educational Codeforces Round 106 (Rated for Div. ...

  9. Educational Codeforces Round 89 (Rated for Div. 2)(A, B, C, D)

    Educational Codeforces Round 89 (Rated for Div. 2) A. Shovels and Swords 思路 题意非常简单,就是得到最多的物品嘛,我们假定a, ...

最新文章

  1. ps怎么制作流体_PS实例教程:制作流体质感背景
  2. Deep Learning(深度学习)学习笔记整理系列之(二)
  3. 【Android 逆向】整体加固脱壳 ( DEX 优化流程分析 | dvmDexFileOpenPartial | dexFileParse | 脱壳点 | 获取 dex 文件在内存中的首地址 )
  4. [C#1] 10-事件
  5. 用3个IO口控制6个LED灯,怎么做到的?查理复用!
  6. 2017广西邀请赛重现赛
  7. 微信、企业微信和支付窗 SDK 三合一,JeeWx-api 1.2.0 版本发布
  8. python之gevent模块实现协程
  9. LabVIEW自带函数实现SQL Server操作(上)
  10. java scan hbase_hbase+java实例,Scan查询所有、get根据rowkey查询一行或一列数据
  11. cmake同时生成动态库与静态库的方法
  12. python 中 enumerate() 函数使用
  13. servlet 与 tomcat版本不匹配的问题
  14. 干货 | 推荐几款实用的思维导图工具
  15. 最新官方版本Fliqlo 炫酷翻盖时钟屏保 多平台
  16. 优锘科技:森模型插件上新:BIM秒变轻量化,模板任选效果
  17. excel单元格斜线_Excel 表格中斜线怎么制作?
  18. 编出个区块链:数据结构的序列化,看看数字货币如何传输数据
  19. 赵小楼《天道》《遥远的救世主》解读(71)客观逻辑与离相的渊源
  20. 3.1 mocha使用allure报告

热门文章

  1. Q10 Regular Expression Matching
  2. 前端微信jssdk智能语音识别,完整案例
  3. jmeter-cvs参数化
  4. uniapp 设置 style 动态背景
  5. VUE:学生列表案例——内部指令v-for与v-on简单应用
  6. c语言如何蓝屏,电脑蓝屏c0000135如何解决?
  7. android zigbee环境监测,基于ZigBee的环境监测系统的设计与实现
  8. 名词解释:耦合、去耦、旁路、滤波
  9. 软件测试之魂:核心测试设计精解
  10. git的基本使用---在coding上进行拉取、提交代码