結果
| 問題 |
No.2939 Sigma Popcount Problem
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2024-10-20 22:54:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 2,000 ms |
| コード長 | 765 bytes |
| コンパイル時間 | 521 ms |
| コンパイル使用メモリ | 40,832 KB |
| 最終ジャッジ日時 | 2025-02-24 22:04:05 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d", &tn);
| ~~~~~^~~~~~~~~~~
main.cpp:38:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
38 | scanf("%lld", &n);
| ~~~~~^~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 2939.cc: No.2939 Sigma Popcount Problem - yukicoder
*/
#include<cstdio>
#include<algorithm>
using namespace std;
/* constant */
const int BN = 40;
/* typedef */
using ll = long long;
/* global variables */
ll dp[BN + 1];
/* subroutines */
/* main */
int main() {
dp[0] = 0;
for (int i = 0; i < BN; i++)
dp[i + 1] = dp[i] * 2 + (1LL << i);
//for (int i = 0; i <= 10; i++) printf(" %lld", dp[i]); putchar('\n');
int tn;
scanf("%d", &tn);
while (tn--) {
ll n;
scanf("%lld", &n);
n++;
ll sum = 0;
for (int i = BN - 1, c = 0; i >= 0; i--) {
int bi = (n >> i) & 1;
if (bi) {
sum += dp[i] + (1LL << i) * c;
c++;
}
}
printf("%lld\n", sum);
}
return 0;
}
tnakao0123