結果

問題 No.737 PopCount
ユーザー weizenweizen
提出日時 2018-09-28 23:15:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,230 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 30,720 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 12:02:26
合計ジャッジ時間 812 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <math.h>

typedef long long ll;
ll MOD = 1000000007;
int main(){
        ll N;
        scanf("%lld",&N);
        int keta = 1;
        ll pow2 = 2;
        while(pow2 < N){
                keta++;
                pow2 *= 2;
        }

        ll ans = 0;
        for(int n = 1; n <= keta; n++){
                ll k = 1;
                for(int j = 1; j < n; j++) k *= 2LL;
                ll origK = k;
                ll x = N/(2LL*origK);

                k %= MOD;
                ll k2 = k*k;
                k2 %= MOD;

                ll tmp = ((3*k2-k)/2+k2*(x-1));
                tmp %= MOD;
                ans += x* tmp;
                ans %= MOD;

                
                if(N >= 2*origK*x+origK){
                        ll tmp1 = ((2*k*x+k)+(N));
                        if(tmp1 % 2 == 0) tmp1 /= 2;
                        tmp1 %= MOD;
                        ll tmp2 = (N-(2*k*x+k)+1);
                        if(tmp2 % 2 == 0) tmp2 /= 2;
                        tmp2 %= MOD;
                        ans += tmp1*tmp2;
                }
                ans %= MOD;
                //printf("k = %lld, x = %lld, ans = %lld\n",k,x,ans);
        }
        printf("%lld\n",ans);
}
0