結果

問題 No.278 連続する整数の和(2)
ユーザー Lay_ecLay_ec
提出日時 2015-09-04 23:52:45
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 79,044 KB
実行使用メモリ 207,172 KB
最終ジャッジ日時 2023-09-26 07:21:58
合計ジャッジ時間 7,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

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=100000000*2;
vector<long long > prime;
bool is_prime[100000000*2+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<prime.size();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;
    cout<<x<<endl;
    
    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