- 250's solution
-
P250's Solution
- @ 2026-4-7 20:34:08
注意到 为奇数时 ,于是答案必定是 的非负整数次幂,逐个判断即可。
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 12;
int a[N];
int main()
{
string n;
while (cin >> n)
{
int s = n.size();
int b = -1;
for (int i = 1; i <= s; i <<= 1)
{
for (int j = 0; j <= 2 * s; j++)
a[j] = 0;
for (int j = 0, k = s - 1; k >= 0; j++, k--)
a[j] = n[k] - '0';
for (int j = 0; j <= s - 1; j++)
{
a[j + i] -= a[j];
a[j] = 0;
if (a[j + i] < 0)
{
a[j + i] += 10;
a[j + i + 1]--;
}
}
bool ok = true;
for (int j = 0; j <= 2 * s; j++)
if (a[j]) ok = false;
if (ok)
{
b = i;
break;
}
}
cout << b << '\n';
}
return 0;
}