結果
問題 | No.237 作図可能性 |
ユーザー |
![]() |
提出日時 | 2019-03-02 19:15:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,979 bytes |
コンパイル時間 | 1,478 ms |
コンパイル使用メモリ | 161,408 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-23 12:27:57 |
合計ジャッジ時間 | 2,436 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 28 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int POW2 = 31; const int FERMAT = 5; int main() { // 1. 入力情報取得. LL A; cin >> A; // 2. フェルマー素数. // -> 4294967297 は, 素数でないとのこと. // https://ja.wikipedia.org/wiki/フェルマー数 LL f[FERMAT] = {3, 5, 17, 257, 65537}; // 3. 作図可能性は, (2 の べき乗) × フェルマー素数 の形とのこと. // https://ja.wikipedia.org/wiki/定規とコンパスによる作図 LL pow2[POW2] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824}; // for(int i = 0; i < 31; i++) cout << (1 << i) << endl; // 4. 集計作業. // -> A = 1000000000 だと, 3, 4, 5, 6, 8, ..., // 808464432, 855638016, 855651072, 858980352, 858993459 の 456個 を出力確認できた. int ans = 0; for(int i = 0; i < 32; i++){ // 2-1. i を 2進数表記. stringstream ss; ss << static_cast<std::bitset<FERMAT>>(i); string bit = ss.str(); // cout << bit << endl; // 2-2. 各フェルマー素数について, 以下のルールで読み替える. // bit の 各桁が 1 なら, フェルマー素数を使用. // bit の 各桁が 0 なら, フェルマー素数を使用しない for(int j = 0; j < POW2; j++){ LL total = pow2[j]; for(int d = 0; d < FERMAT; d++){ int b = bit[d] - '0'; if(b != 0) total *= b * f[d]; } if(total >= 3 && total <= A){ ans++; // cout << total << endl; } } } // 5. 後処理. cout << ans << endl; return 0; }