Created
August 28, 2015 02:48
-
-
Save asi1024/a2d2090223bc5da51250 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#define REP(i,n) for(int i=0;i<(int)(n);i++) | |
#define ALL(x) (x).begin(),(x).end() | |
using namespace std; | |
typedef long long ll; | |
typedef array<ll,64> Array; | |
typedef pair<ll,ll> P; | |
Array f(ll n) { | |
Array res; | |
res.fill(0); | |
if (n <= 1) return res; | |
if (n % 2) { | |
res = f(n - 1); | |
REP(i,64) res[i] += ((n - 1) >> i) & 1LL; | |
} | |
else { | |
res[0] = n / 2; | |
Array a = f(n / 2); | |
REP(i,63) res[i+1] = a[i] * 2; | |
} | |
return res; | |
} | |
ll solve(const Array &ary, ll num) { | |
ll sum = 0; | |
int bit = 0; | |
REP(i,64) if (ary[i] > 0) bit = i; | |
for (int i = bit; i >= 0; --i) { | |
if (ary[i] == 0) continue; | |
if (num == ary[i]) sum += (1LL << i); | |
else return sum + (1LL << i) + ary[i]; | |
} | |
return sum + 1; | |
} | |
int main() { | |
int n; | |
while (scanf("%d", &n) && n) { | |
Array ary; | |
ary.fill(0); | |
REP(i,n) scanf("%lld", &ary[i]); | |
ll low = -1, high = -1, cnt = 0; | |
for (int i = -1; i < 2; ++i) { | |
ll num = ary[0] * 2 + i; | |
ll h = solve(ary, num), l = h - num; | |
if (l < 1 || num <= 0 || h > 1000000000000000001LL) continue; | |
Array ah = f(h), lh = f(l); | |
bool flag = true; | |
REP(j,64) if (lh[j] + ary[j] != ah[j]) flag = false; | |
if (flag) { ++cnt; low = l; high = h; } | |
} | |
if (cnt == 0) printf("None\n"); | |
else if (cnt > 1) printf("Many\n"); | |
else printf("%lld %lld\n", low, high-1); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment