uva11549 Floyd判圈法

题意:

给两个数n, k,每次将k平方取k的前n位,问所有出现过的数的最大值

原来这就是floyd判圈法。。

 #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string> template<typename Q> Q read(Q& x) {
static char c;
static bool f;
for(f = ; c = getchar(), !isdigit(c); ) if(c == '-') f = ;
for(x = ; isdigit(c); c = getchar()) x = x * + c - '';
if(f) x = -x; return x;
}
template<typename Q> Q read() {
static Q x; read(x); return x;
} typedef long long LL; int next(int n, int x) {
LL x2 = (LL) x * x;
int len = ;
for(LL t = x2; t; t /= ) len++;
if(len > n) for(int t = len - n; t--; x2 /= );
return x2;
} int main() {
#ifdef DEBUG
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#endif int T = read<int>();
while(T--) {
int n = read<int>(), k = read<int>();
int ans = k, k1 = k, k2 = k;
do {
k1 = next(n, k1);
k2 = next(n, k2); ans = std::max(ans, k2);
k2 = next(n, k2); ans = std::max(ans, k2);
}while(k1 != k2);
printf("%d\n", ans);
} return ;
}
上一篇:VS 2012 显示Link的参数


下一篇:取出csv文件中的中文评论数据