题目链接:https://vjudge.net/problem/Gym-100519I
解题思路:
先挂在这里
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int mx = 3e5+10;
bool vis[mx];
int top,pri[mx];
void init(){
for(int i=2;i<mx;i++){
if(!vis[i]) pri[top++] = i;
for(int j=0;j<top&&pri[j]*i<mx;j++)
{
vis[pri[j]*i] = 1;
if(i%pri[j]==0) break;
}
}
}
char buff[100];
int res[100];
bool check(ll P){
int l = 1,r = P - 1;
if(res[0]) r = (P-1)/2;
else l = (P+1)/2;
ll m = 2,L,R,t;
for(int i=1;i<41;i++,m<<=1){
L = l * m,R = r * m,t = L / P;
L -= t*P,R -= t*P;
if(res[i]) R = min(R,(P-1)/2);
else L = max(L,(P+1)/2);
L += t*P,R += t*P;
l = (L-1) / m + 1,r = R / m;
if(l>r) return 0;
}
return 1;
}
int main(){
init();
int n;scanf("%d",&n);
for(int i=0;i<41;i++){
puts("2");
fflush(stdout);
scanf("%s",buff);
if(buff[0]=='O'){
return 0;
}
res[i] = buff[0] == '>';
}
for(int i=0;i<top;i++)
if(check(pri[i])){
printf("%d\n",pri[i]);
fflush(stdout);
break;
}
return 0;
}
标签:NONE,100519I,int,Gym,long,init,mx From: https://blog.51cto.com/u_12468613/6384511