結果

問題 No.1260 たくさんの多項式
ユーザー chocorusk
提出日時 2020-10-16 22:11:32
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 1,701 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 125,408 KB
最終ジャッジ日時 2025-01-15 08:32:17
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[2000010], invf[2000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    ll n; cin>>n;
    ll d=0;
    for(ll i=1; i*i<=n; i++){
        d=i;
    }
    ll ans=0;
    auto calc=[&](ll m){
        if(m%2==0) return m/2%MOD*((m+1)%MOD)%MOD;
        else return ((m+1)/2%MOD)*(m%MOD)%MOD;
    };
    for(ll i=1; i<=d; i++){
        ll m=n/i;
        ll m1=max(d, n/(i+1));
        ans+=((n+i)%MOD)*((m-m1)%MOD);
        ans+=(MOD-i)*(calc(m)-calc(m1)+MOD);
        ans%=MOD;
    }
    for(ll i=2; i<=d; i++){
        ll n1=n;
        while(n1){
            ans+=n1%i;
            n1/=i;
        }
    }
    ans%=MOD;
    cout<<ans<<endl;
    return 0;
}
0