标签:
2 10 2 10 3
13 14
#include <bits/stdc++.h> using namespace std; #define prt(k) cerr<<#k" = "<<k<<endl typedef long long ll; const int N = 63; int p[N]; ll n; int r; int sign[N]; vector<int> rc; vector<int> mi; void get_rc() { rc.clear(); for (int x : mi) { int n = rc.size(); if (abs(x) > r) break; for (int j=0;j<n;j++) if (abs(x*rc[j]) <= 62) rc.push_back(x*rc[j]); rc.push_back(x); } } ll f(ll n, int r) { if (n==1) return 0; ll ans = n - 1; for (ll x:rc) { ll t = pow(n+0.5, 1.0/abs(x) ) - 1; if (x < 0) ans -= t; else ans += t; } return ans ; } int main() { for (int i=1;i<N;i++) p[i] = i; for (int i=2;i<N;i++) if (p[i]==i) { for (int j=i+i; j<N; j+=i) p[j] = i; mi.push_back(-i); } int re, ca=1; scanf("%d", &re); while (re--) { scanf("%I64d%d", &n, &r); get_rc(); ll x = n ; while (1) { ll t = f(x, r); if (t >= n) break; x += n - t; } printf("%I64d\n", x); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/oilover/article/details/47045227