結果

問題 No.278 連続する整数の和(2)
ユーザー Lay_ecLay_ec
提出日時 2015-09-04 23:47:58
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,501 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 78,972 KB
実行使用メモリ 22,980 KB
最終ジャッジ日時 2023-09-26 07:20:30
合計ジャッジ時間 3,610 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
22,200 KB
testcase_01 AC 106 ms
21,108 KB
testcase_02 AC 87 ms
21,980 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 107 ms
20,840 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>
#include <stack>

using namespace std;

__int128 gcd(__int128 x,__int128 y){
    return y==0 ? x : gcd(y,x%y);
}

const int N=10000000;
vector<long long > prime;
bool is_prime[10000000+1];

void era(){
    for(int i=0;i<N+1;i++) is_prime[i]=true;
    is_prime[0]=is_prime[1]=false;
    for(int i=2;i<=N;i++){
        if(is_prime[i]){
            prime.push_back(i);
            for(int j=2*i;j<=N;j+=i) is_prime[j]=false;
        }
    }
}

long long my_pow(long long x,long long n){
    long long res=1;
    while(n){
        if(n&1) res*=x;
        x=x*x;
        n>>=1;
    }
    return res;
}

bool check(long long x){

    for(int i=0;prime[i]*prime[i]<=x;i++){
        if(x%prime[i]==0) return false;
    }
    return true;
}

int main()
{
    era();

    long long n;
    cin>>n;
    
    __int128 n128=n;
    __int128 x128=gcd(n128,(1+n128)*n128/2);
    long long x=x128;
    
    if(x!=1 && check(x)){
        cout<<1+x<<endl;
        return 0;
    }
    
    long long res=1;
    for(int i=0;i<prime.size();i++){
        long long cnt=1;
        while(x%prime[i]==0){
            x/=prime[i]; cnt++;
        }
        if(cnt!=1) cout<<prime[i]<<endl;
        res*=(1-my_pow(prime[i],cnt))/(1-prime[i]);
        
    }
    cout<<res<<endl;

    return 0;
}
0