Submission #129490

# Submission time Handle Problem Language Result Execution time Memory
129490 2019-07-12T09:49:18 Z E869120 Binary Subsequences (info1cup17_binary) C++14
100 / 100
733 ms 1348 KB
#include <iostream>
#include <algorithm>
using namespace std;

bool used[1 << 20];

void init(int pos) {
	for (int i = 2; i <= pos; i++) {
		if (used[i] == true || pos%i != 0) continue;
		for (int j = i; j <= pos; j += i) used[j] = true;
	}
}

int main() {
	int T; cin >> T;
	for (int i = 1; i <= T; i++) {
		int A; cin >> A;
		
		for (int j = 1; j <= A + 2; j++) used[j] = false;
		init(A + 2);

		long long cnt = 0, ret = (1 << 30), mask = 0;
		for (int j = 1; j <= A + 2; j++) {
			if (used[j] == true) continue;
			cnt++;

			if (j > ((A + 2) >> 1) + 1) continue;

			int t1 = j, t2 = (A + 2) - j; long long mask1 = 0, lens = 0;
			while (t1 >= 1 && t2 >= 1) {
				if (t1 < t2) { t2 -= t1; }
				else { mask1 += (1LL << lens); t1 -= t2; }
				lens++; if (lens == 60) break;
			}
			if (ret > lens) {
				ret = lens; mask = mask1;
			}
		}

		cout << cnt << endl;
		for (int j = 0; j < ret - 1; j++) {
			if (j) cout << " "; cout << (mask / (1LL << j)) % 2;
		}
		cout << endl;
	}
	return 0;
}

Compilation message

binary.cpp: In function 'int main()':
binary.cpp:42:4: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    if (j) cout << " "; cout << (mask / (1LL << j)) % 2;
    ^~
binary.cpp:42:24: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    if (j) cout << " "; cout << (mask / (1LL << j)) % 2;
                        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 89 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 376 KB Output is correct
2 Correct 54 ms 376 KB Output is correct
3 Correct 51 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 1348 KB Output is correct
2 Correct 733 ms 1272 KB Output is correct
3 Correct 592 ms 1272 KB Output is correct