結果

問題 No.2937 Sigma Plus Problem
ユーザー yuusaan
提出日時 2024-10-09 11:59:26
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 300 ms
コード長 467 bytes
コンパイル時間 3,069 ms
コンパイル使用メモリ 244,188 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-09 11:59:30
合計ジャッジ時間 3,903 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ull = unsigned long long;

int main(){
    ull N;
    cin >> N;
    ull ans = 0;
    ull a = sqrt(N);//整数型において、sqrt(x)はxの平方根の切り捨て
    ull b = 0;
    for(ull i = 1;i <= a;i++)b += i;//1 + 2 + ... + a

    for(ull i = 0;i < a;i++){
        ans += i * a * a + b;//ia^2+b
    }

    for(ull i = a * a + 1;i <= N;i++)ans += i;//(a^2+1) + (a^2+2) + ... + N

    cout << ans << endl;
}
0