제출 #129490

#제출 시각아이디문제언어결과실행 시간메모리
129490E869120Binary Subsequences (info1cup17_binary)C++14
100 / 100
733 ms1348 KiB
#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;
}

컴파일 시 표준 에러 (stderr) 메시지

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...