結果

問題 No.1276 3枚のカード
ユーザー chocorusk
提出日時 2020-10-30 21:53:33
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 321 ms / 2,000 ms
+ 268µs
コード長 1,212 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,115 ms
コンパイル使用メモリ 154,776 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-29 16:55:40
合計ジャッジ時間 12,589 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
using ll=long long;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll calc(ll r){
    ll sq=1;
    ll ans=0;
    for(ll i=1; i*i<=r; i++){
        sq=i;
        ans+=i*(r/i-r/(i+1));
    }
    for(ll i=1; i<=r/(sq+1); i++){
        ans+=r/i;
    }
    ans%=MOD;
    return ans;
}
int main()
{
    ll n; cin>>n;
    vector<ll> v;
    ll sq=1;
    for(ll i=1; i*i<=n; i++){
        sq=i;
        if(n/i-n/(i+1)>0) v.push_back(i);
    }
    for(ll i=1; i<=n/(sq+1); i++) v.push_back(n/i);
    sort(v.begin(), v.end());
    ll ans=0;
    for(auto x:v){
      ll z=n/x-n/(x+1);
        ans+=(x-1)*(n+1-x)%MOD*z;
        ans+=MOD-(x-1)*(calc(n/x)-calc(n/(x+1))+MOD)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}
0