結果

問題 No.1276 3枚のカード
ユーザー chocorusk
提出日時 2020-10-30 21:53:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,545 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 1,462 ms
コンパイル使用メモリ 129,928 KB
最終ジャッジ日時 2025-01-15 17:14:39
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

#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