結果

問題 No.278 連続する整数の和(2)
ユーザー Lay_ecLay_ec
提出日時 2015-09-05 00:17:16
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 779 bytes
コンパイル時間 500 ms
実行使用メモリ 3,504 KB
最終ジャッジ日時 2023-01-12 15:50:24
合計ジャッジ時間 1,634 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
3,368 KB
testcase_01 AC 2 ms
3,424 KB
testcase_02 AC 23 ms
3,444 KB
testcase_03 AC 2 ms
3,440 KB
testcase_04 AC 2 ms
3,452 KB
testcase_05 AC 1 ms
3,504 KB
testcase_06 AC 1 ms
3,428 KB
testcase_07 AC 2 ms
3,368 KB
testcase_08 AC 1 ms
3,372 KB
testcase_09 AC 2 ms
3,368 KB
testcase_10 AC 2 ms
3,416 KB
testcase_11 AC 4 ms
3,412 KB
testcase_12 AC 1 ms
3,504 KB
testcase_13 AC 16 ms
3,368 KB
testcase_14 AC 3 ms
3,376 KB
testcase_15 AC 10 ms
3,376 KB
testcase_16 AC 4 ms
3,440 KB
testcase_17 AC 3 ms
3,368 KB
権限があれば一括ダウンロードができます

ソースコード

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;

long long calc(long long x){
    long long res=1;
    for(long long i=2;i*i<=x;i++){
        long long tmp=i;
        while(x%i==0){
            x/=i; tmp*=i;
        }

        //(1+i^1+i^2+...+i^(n-1))=(i^n)/(i-1)
        //tmp=i^n
        res*=(tmp-1)/(i-1);
    }
    
    //残ったxは素数
    if(x!=1){
        res*=(1+x);
    }
    
    return res;
}

int main()
{

    long long n;
    cin>>n;
    
    long long x;
    if(n%2) x=n;
    else x=n/2;

    cout<<calc(x)<<endl;

    return 0;
}
0