fork(1) download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<queue>
  5. #include<map>
  6. #include<utility>
  7. #include<set>
  8. #include<stack>
  9. #include<list>
  10. #include<deque>
  11. #include<bitset>
  12. #include<iomanip>
  13. #include<cstring>
  14. #include<sstream>
  15. #include<cstdio>
  16. #include<cstdlib>
  17. #include<climits>
  18. #include<cmath>
  19. #include<cctype>
  20.  
  21.  
  22. #define pb push_back
  23. #define mp make_pair
  24. #define rep(i,a,b) for(int i=a;i<=b;i++)
  25. #define ren(i,a,b) for(int i=a;i>=b;i--)
  26. #define ff first
  27. #define ss second
  28. #define pll pair<long long int,long long int>
  29. #define pii pair<int,int>
  30. #define vll vector<long long int>
  31. #define vii vector<int>
  32. #define gi(n) scanf("%d",&n)
  33. #define gll(n) scanf("%lld",&n)
  34. #define gstr(n) scanf("%s",n)
  35. #define gl(n) cin >> n
  36. #define oi(n) printf("%d",n)
  37. #define oll(n) printf("%lld",n)
  38. #define ostr(n) printf("%s",n)
  39. #define ol(n) cout << n
  40. #define os cout<<" "
  41. #define on cout<<"\n"
  42. #define o2(a,b) cout<<a<<" "<<b
  43. #define all(n) n.begin(),n.end()
  44. #define present(s,x) (s.find(x) != s.end())
  45. #define cpresent(s,x) (find(all(s),x) != s.end())
  46. #define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
  47. using namespace std;
  48.  
  49. typedef unsigned long long int ll;
  50. //typedef long long int ll;
  51. typedef vector<vector<ll> > mat;
  52.  
  53. bool of(ll a,ll b)
  54. {
  55. if(((a*b)/b)!=a)return true;
  56. return false;
  57. }
  58.  
  59. vector<ll> v[15],v1;
  60.  
  61. int main()
  62. {ios_base::sync_with_stdio(false);
  63. //freopen("output.txt","w",stdout);
  64. int t;
  65. gl(t);
  66.  
  67. ll x=2;
  68.  
  69. while(1)
  70. {
  71. v[2].pb(x);
  72. if(of(x,2))
  73. break;
  74. x*=2;
  75. }
  76.  
  77. tr(v[2],it)v1.pb(*it);
  78.  
  79. x=3;
  80. while(1)
  81. {
  82. v[3].pb(x);
  83. tr(v1,it)
  84. {
  85. ll y=*it;
  86. if(of(y,x))break;
  87. v[3].pb(y*x);
  88. }
  89. if(of(x,3))break;
  90. x*=3;
  91. }
  92.  
  93. tr(v[3],it)v1.pb(*it);
  94. sort(all(v1));
  95.  
  96. x=5;
  97.  
  98. while(1)
  99. {
  100. v[5].pb(x);
  101. tr(v1,it)
  102. {
  103. ll y=*it;
  104. if(of(y,x))break;
  105. v[5].pb(y*x);
  106. }
  107. if(of(x,5))break;
  108. x*=5;
  109. }
  110.  
  111. tr(v[5],it)v1.pb(*it);
  112. sort(all(v1));
  113.  
  114. x=7;
  115. while(1)
  116. {
  117. v[7].pb(x);
  118. tr(v1,it)
  119. {
  120. ll y=*it;
  121. if(of(y,x))break;
  122. v[7].pb(y*x);
  123. }
  124. if(of(x,7))break;
  125. x*=7;
  126. }
  127.  
  128. tr(v[7],it)v1.pb(*it);
  129. sort(all(v1));
  130.  
  131. x=11;
  132.  
  133. while(1)
  134. {
  135. v[11].pb(x);
  136. tr(v1,it)
  137. {
  138. ll y=*it;
  139. if(of(y,x))break;
  140. v[11].pb(y*x);
  141. }
  142. if(of(x,11))break;
  143. x*=11;
  144. }
  145.  
  146. tr(v[11],it)v1.pb(*it);
  147. sort(all(v1));
  148. sort(all(v[2]));
  149. sort(all(v[3]));
  150. sort(all(v[5]));
  151. sort(all(v[7]));
  152. sort(all(v[11]));
  153. //ol(v[2].size());on;
  154. //ol(v[3].size());on;
  155. //ol(v[5].size());on;
  156. //ol(v[7].size());on;
  157. //ol(v[11].size());on;
  158. while(t--)
  159. {
  160. ll a,k,n;
  161. cin>>a>>k>>n;
  162. if(n==0)
  163. {
  164. ol(a);on;
  165. }
  166. else
  167. {
  168. int idx=lower_bound(all(v[k]),a)-v[k].begin();
  169. //ol(v[k][idx+1]);on;
  170. ol(v[k][idx+n-1]);on;
  171. }
  172. }
  173. return 0;
  174. }
  175.  
Runtime error #stdin #stdout 0.05s 13368KB
stdin
Standard input is empty
stdout
Standard output is empty