結果

問題 No.278 連続する整数の和(2)
ユーザー TatamoTatamo
提出日時 2016-11-01 18:09:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,444 bytes
コンパイル時間 1,687 ms
コンパイル使用メモリ 63,840 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-08-16 12:19:08
合計ジャッジ時間 2,043 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 7 ms
4,384 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 1 ms
4,384 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<utility>
#include<vector>

using namespace std;
#define cerr cerr << "[DBG] "
#define DBG(x) cerr << #x << ": " << x << endl
// http://genkisugimoto.com/jp/blog/procon/2015/04/15/print-debug-technique-in-cpp.html
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { for (int i = 0; i < (int)v.size(); ++i) { s << v[i]; if (i < (int)v.size() - 1) s << "\t"; } return s; }

typedef long long ll;

int main(){
	ll n;
	cin >> n;
	// n:偶数→ n/2の約数の総和
	// n:奇数→ nの約数の総和
	ll m;
	if(n%2 == 0){
		m = n/2;
	}
	else {
		m = n;
	}

	ll x = m;
	vector<pair<ll, ll>> c;
	for(ll i=2; i*i<=m; i++){
		if(m%i != 0) {
			i+=1;
			continue;
		}
		ll cnt = 0;
		while(x%i == 0){
			x /= i;
			cnt+=1;
		}
		c.push_back(make_pair(i,cnt));
		i+=1;
	}
	if(x > 1) {
		bool flg = true;
		for(int i=0; i<(int)c.size(); i++){
			if(c[i].first == x){
				c[i].second += 1;
				flg = false;
				break;
			}
		}
		if(flg){
			c.push_back(make_pair(x, 1));
		}
	}
	//cerr << c << endl;

	ll result = 1;
	for(ll i=0; i<(int)c.size(); i++){
		ll p = c[i].first;
		ll cnt = c[i].second;

		ll tmp = 1;
		ll x = 0;
		for(ll ii=0; ii<=cnt; ii++){
			x += tmp;
			if(ii<cnt) tmp *= p;
		}
		result *= x;
	}

	cout << result << endl;

	return 0;
}
0