結果

問題 No.237 作図可能性
ユーザー @abcde@abcde
提出日時 2019-03-02 19:15:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,979 bytes
コンパイル時間 1,157 ms
コンパイル使用メモリ 147,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 16:57:03
合計ジャッジ時間 2,356 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    
}
0