結果

問題 No.278 連続する整数の和(2)
ユーザー Lay_ecLay_ec
提出日時 2015-09-04 23:48:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,503 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 78,584 KB
実行使用メモリ 23,056 KB
最終ジャッジ日時 2023-09-26 07:21:04
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
20,984 KB
testcase_01 AC 119 ms
21,136 KB
testcase_02 AC 117 ms
21,592 KB
testcase_03 AC 113 ms
21,724 KB
testcase_04 AC 112 ms
21,224 KB
testcase_05 AC 112 ms
22,132 KB
testcase_06 AC 109 ms
21,472 KB
testcase_07 AC 122 ms
21,288 KB
testcase_08 AC 114 ms
21,300 KB
testcase_09 AC 110 ms
21,076 KB
testcase_10 WA -
testcase_11 AC 109 ms
21,512 KB
testcase_12 AC 103 ms
20,848 KB
testcase_13 AC 117 ms
21,224 KB
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