結果
問題 |
No.3118 Increment or Multiply
|
ユーザー |
|
提出日時 | 2025-04-05 14:54:21 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 582 bytes |
コンパイル時間 | 3,707 ms |
コンパイル使用メモリ | 274,156 KB |
実行使用メモリ | 16,072 KB |
最終ジャッジ日時 | 2025-04-12 16:43:15 |
合計ジャッジ時間 | 7,121 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 1 |
other | AC * 5 TLE * 1 -- * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 998244353; constexpr ll twoinv = 499122177; ll t,n,a; ll f(ll i){ if(i == n) return 0; if(i * a > n) return (n - i) % mod; return (f(a * i) + 1) % mod; } int main(){ cin >> t; while(t--){ cin >> n >> a; if(a == 1){ cout << ((((n % mod) * ((n - 1) % mod)) % mod) * twoinv ) % mod<< endl; continue; } ll ans = 0; for(ll i = 1; i <= n; i++){ ans += f(i); } cout << ans << endl; } }