結果

問題 No.737 PopCount
ユーザー greentea011greentea011
提出日時 2018-10-01 15:18:41
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 712 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-20 14:16:44
合計ジャッジ時間 2,792 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
13,884 KB
testcase_01 AC 7 ms
6,816 KB
testcase_02 AC 7 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 6 ms
6,944 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%ld", &a);
      |     ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

long popcount(long bits)
{
    bits = (bits & 0x5555555555555555) + (bits >> 1 & 0x5555555555555555);
    bits = (bits & 0x3333333333333333) + (bits >> 2 & 0x3333333333333333);
    bits = (bits & 0x0f0f0f0f0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f0f0f0f0f);
    bits = (bits & 0x00ff00ff00ff00ff) + (bits >> 8 & 0x00ff00ff00ff00ff);
    bits = (bits & 0x0000ffff0000ffff) + (bits >>16 & 0x0000ffff0000ffff);
    return (bits & 0x00000000ffffffff) + (bits >>32 & 0x00000000ffffffff);
}

int main() {
    long a;
    scanf("%ld", &a);
    long sum=0;
    for (long i = a; i != 0; i--) {
        sum = (sum + (i * popcount(i)) % 1000000007) % 1000000007;
    }
    printf("%ld", sum);
    return 0;
}
0