結果

問題 No.1573 Divisor Function
コンテスト
ユーザー
提出日時 2021-07-13 21:56:47
言語 C++14
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 812 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 793 ms
コンパイル使用メモリ 106,304 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2026-03-24 01:27:21
合計ジャッジ時間 1,669 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/string:53,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/locale_classes.h:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ios_base.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ios:46,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:43,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
In function 'constexpr const _Tp& std::max(const _Tp&, const _Tp&) [with _Tp = long long int]',
    inlined from 'int main()' at main.cpp:30:34:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_algobase.h:263:7: warning: 'sq' may be used uninitialized [-Wmaybe-uninitialized]
  263 |       if (__a < __b)
      |       ^~
main.cpp: In function 'int main()':
main.cpp:21:28: note: 'sq' was declared here
   21 |         long long ans = 0, sq;
      |                            ^~

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 998244353;
int main() {
	long long n, m;
	cin >> n >> m;
	long long ans = 0, sq;
	for (long long i = 1; (i <= m && i * i <= n); i++) {
		long long a = n / i;
		ans += a * (a + 1) / 2 * i + a * i % mod;
		ans %= mod;
		sq = i;
	}
	for (long long i = 1; i * i < n; i++) {
		long long b = n / i, c = n / (i + 1);
		b = max(sq, min(b, m)), c = max(sq, min(c, m));
		ans += i * (i + 1) / 2 * (b + c + 1) * (b - c) / 2;
		ans %= mod;
		ans += (b + c + 1) * (b - c) / 2 * i;
		ans %= mod;
	}
	cout << ans << endl;
}
0