結果

問題 No.278 連続する整数の和(2)
ユーザー Bantako
提出日時 2018-05-30 15:30:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 167,920 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-30 08:13:39
合計ジャッジ時間 3,079 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   18 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
bool prime[2000010];
int factor[2000010];
ll gcd (ll a,ll b){
    if(!b)return a;
    return gcd(b,a%b);
}
ll powint(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powint(x*x,n/2);
    if(n % 2 == 1)ans = ans * x;
    return ans;
}
main(){
    ll N,g;
    cin >> N;
    
    if(N % 2) g = N;
    else g = N/2;
    
    //g = N;
    for(int i = 2;i*i <= 2000000;i++){
        if(prime[i])continue;
        for(int j = i*2;j <= 2000000;j+=i)prime[j] = 1;
    }
    loop:
    for(int i = 2;i <= 2000000;i++){
        while(!prime[i] && g % i == 0){
            factor[i]++;
            g /= i;
            //goto loop;
        }
    }
    ll ans = 1;
    for(int i = 2;i <= 2000000;i++){
        //(r^n - 1) / (r - 1)
        ans *= (powint(i,factor[i]+1)-1)/(i-1);
    }
    if(g != 1)ans *= (g+1);
    cout << ans << endl;
}
0