結果

問題 No.278 連続する整数の和(2)
ユーザー Bantako
提出日時 2017-08-18 12:13:00
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 890 bytes
コンパイル時間 1,653 ms
コンパイル使用メモリ 167,052 KB
実行使用メモリ 5,504 KB
最終ジャッジ日時 2024-12-23 09:14:01
合計ジャッジ時間 2,613 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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,sum;
    cin >> N;
    sum = (N-1)*N/2;
    if(N % 2) g = N;
    else g = N/2;

    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 <= 200000;i++){
        if(!prime[i] && g % i == 0){
            factor[i]++;
            g /= i;
            goto loop;
        }
    }
    ll ans = 1;
    for(int i = 2;i <= 200000;i++){
        ans *= (powint(i,factor[i]+1)-1)/(i-1);
    }
    if(g != 1)ans *= (g+1);
    cout << ans << endl;
}
0