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
  1. 3
    7 22 1
    7 22 2
    7 22 3
output
  1. 9
    13
    15
input
  1. 5
    42 42 42
    43 43 43
    44 44 44
    45 45 45
    46 46 46
output
  1. 187
    87
    139
    128
    141
  2.  
  3. 题意 q个询问 大于x,第k个与p互质的数
    解析 对于一个数 mid 我们可以容斥算出1-mid p互质的数有多少,所以二分答案就可以了。
    AC代码
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define mp make_pair
  4. #define fi first
  5. #define se second
  6. #define all(a) (a).begin(), (a).end()
  7. #define fillchar(a, x) memset(a, x, sizeof(a))
  8. #define huan printf("\n")
  9. #define debug(a,b) cout<<a<<" "<<b<<" "<<endl
  10. #define ffread(a) fastIO::read(a)
  11. using namespace std;
  12. typedef long long ll;
  13. typedef pair<int,int> pii;
  14. const int maxn=1e4+;
  15. const ll mod=;
  16. ll yinzi[maxn],cnt;
  17. void euler(ll n)
  18. {
  19. cnt=;
  20. ll a=n;
  21. for(ll i=; i*i<=a; i++)
  22. {
  23. if(a%i==)
  24. {
  25. yinzi[cnt++]=i;
  26. while(a%i==)
  27. a/=i;
  28. }
  29. }
  30. if(a>)
  31. yinzi[cnt++]=a;
  32. }
  33. ll solve(ll n)
  34. {
  35. ll ans=;
  36. for(ll i=; i<(<<cnt); i++)
  37. {
  38. ll temp=,jishu=;
  39. for(ll j=; j<cnt; j++)
  40. {
  41. if(i&(<<j))
  42. temp=temp*yinzi[j],jishu++;
  43. }
  44. if(jishu==)
  45. continue;
  46. if(jishu&)
  47. ans+=n/temp;
  48. else
  49. ans-=n/temp;
  50. }
  51. return ans;
  52. }
  53. int main()
  54. {
  55. ll t,n,m,k;
  56. scanf("%lld",&t);
  57. while(t--)
  58. {
  59. scanf("%lld%lld%lld",&m,&n,&k);
  60. euler(n);
  61. ll ans1=m-solve(m);
  62. ll l=m+,r=1e7;
  63. while(l<=r)
  64. {
  65. ll mid=(l+r)/;
  66. ll cur=mid-solve(mid)-ans1;
  67. if(cur<k)
  68. l=mid+;
  69. else
  70. r=mid-;
  71. }
  72. printf("%lld\n",r+);
  73. }
  74. }

Educational Codeforces Round 37 (Rated for Div. 2) G的更多相关文章

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

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

  3. Educational Codeforces Round 37 (Rated for Div. 2) 920E E. Connected Components?

    题 OvO http://codeforces.com/contest/920/problem/E 解 模拟一遍…… 1.首先把所有数放到一个集合 s 中,并创建一个队列 que 2.然后每次随便取一 ...

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

  5. [Codeforces]Educational Codeforces Round 37 (Rated for Div. 2)

    Water The Garden #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h ...

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

  7. Educational Codeforces Round 58 (Rated for Div. 2) G 线性基

    https://codeforces.com/contest/1101/problem/G 题意 一个有n个数字的数组a[],将区间分成尽可能多段,使得段之间的相互组合异或和不等于零 题解 根据线性基 ...

  8. 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即可.(感 ...

  9. Educational Codeforces Round 51 (Rated for Div. 2) G. Distinctification(线段树合并 + 并查集)

    题意 给出一个长度为 \(n\) 序列 , 每个位置有 \(a_i , b_i\) 两个参数 , \(b_i\) 互不相同 ,你可以进行任意次如下的两种操作 : 若存在 \(j \not = i\) ...

随机推荐

  1. spring mvc 解决 Could not open ServletContext resource [/WEB-INF/dispatcher-servlet.xml] 异常

    org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document fro ...

  2. 为Qt添加SSL支持

    目标:为Qt添加SSL支持,使得应用可以发送HTTPS请求 环境:win7,Qt4.8.6 步骤: 1.到http://slproweb.com/products/Win32OpenSSL.html下 ...

  3. monkeyrunner 简单用例编写

    monkeyrunnerfrom com.android.monkeyrunner import MonkeyRunner,MonkeyDevice,MonkeyImagedevice = Monke ...

  4. mysql登录(linux)

    一.修改配置文件 查询路径 find / -name my.cnf 修改文件 vi my.cnf [mysqld]下面加上skip-grant-tables 二.登录数据库 重启mysql servi ...

  5. Java集合(六)--ArrayList、LinkedList和Vector对比

    在前两篇博客,学习了ArrayList和LinkedList的源码,地址在这: Java集合(五)--LinkedList源码解读 Java集合(四)--基于JDK1.8的ArrayList源码解读 ...

  6. mkdir与makedirs

    mkdir创建的是一级目录 makedirs可以创建多级目录 mkdir -p可以递归创建目录

  7. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1146

    问题介绍:   com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown error 1146 MySql语法错误, 但是错 ...

  8. No-6.用户权限相关命令

    用户权限相关命令 目标 用户 和 权限 的基本概念 用户管理 终端命令 组管理 终端命令 修改权限 终端命令 01. 用户 和 权限 的基本概念 1.1 基本概念 用户 是 Linux 系统工作中重要 ...

  9. JS实现两版本号大小比较

    JavaScript实现版本号比对(含字母) 昨天,有一道面试题,要求是这样的: 用你熟悉的编程语言,实现一个比较任意两个软件版本号大小的函数,如1.2.3a与1.2.4b进行比较,后者版本号更大,要 ...

  10. mysql alter修改数据库表结构用法

    1.alter操作表字段 (1)增加字段 alter table 表名 add 字段名 字段类型: alter table student add name varchar(10): (2)修改字段 ...