XDU 1011
解法1:TLE
#include<stdio.h> int main() { long long n; //freopen("in.txt","r",stdin); while(scanf("%lld",&n)!=EOF){ long long i=1,s=0; while(s<=n){ s=i*i; i++; } if(i%2!=0) printf("odd\n"); else printf("even\n"); } return 0; }
解法2:AC
#include<bits/stdc++.h> using namespace std; #define maxn 1e10 long long sum(long long t) { return t*(t+2); } int main() { long long n; //freopen("in.txt","r",stdin); while(scanf("%lld",&n)!=EOF) { long long r=maxn,l=1,mid=(maxn+1)/2; while(1) { if(sum(mid)>n) { if(sum(mid-1)==n){ mid--; break; } if(sum(mid-1)<n) break; r=mid; mid=(l+r)/2; } else{ if(sum(mid+1)>=n){ mid++; break; } l=mid; mid=(l+r)/2; } } if(mid%2) printf("odd\n"); else printf("even\n"); } }