結果

問題 No.3377 Sigma Index × A Problems
コンテスト
ユーザー The Forsaking
提出日時 2025-12-05 22:31:22
言語 C++17
(gcc 13.3.0 + boost 1.89.0)
結果
AC  
実行時間 378 ms / 3,000 ms
コード長 864 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,678 ms
コンパイル使用メモリ 194,612 KB
実行使用メモリ 7,848 KB
最終ジャッジ日時 2025-12-05 22:31:29
合計ジャッジ時間 6,154 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void solve()’:
main.cpp:15:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |     scanf("%lld", &n);
      |     ~~~~~^~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   29 |     scanf("%d", &T);
      |     ~~~~~^~~~~~~~~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
const int N = 2000010, MOD = 998244353, INF = 0x3f3f3f3f;
int n, m, w[N];


ll qmi(ll a, ll b, ll c) { ll res = 1; while (b) { if (b & 1) res = res * a % c; a = a * a % c; b >>= 1; } return res; }

void solve() {
    ll n;
    scanf("%lld", &n);
    ll inv2 = qmi(2, MOD - 2, MOD);
    ll res = 0;
    for (ll i = 1, p = 1; i < 42; i++, p = p * i / __gcd(p, i)) {
        if (p > n) break;
        ll t = (n / p - 1 + MOD) % MOD, g = p % MOD, iv = p / i % MOD;
        if (n / p - 1) res = (res + g * ((p / i * (1 + t) % MOD) * t % MOD * inv2 % MOD) % MOD) % MOD;
        res = (res + (n / p * p / i) % MOD * ((n - n / p * p + 1) % MOD)) % MOD;
    }
    printf("%lld\n", res);
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) solve();
    return 0;
}
0