結果
| 問題 |
No.888 約数の総和
|
| コンテスト | |
| ユーザー |
toririm_
|
| 提出日時 | 2019-11-30 15:26:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 944 bytes |
| コンパイル時間 | 1,778 ms |
| コンパイル使用メモリ | 173,728 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-21 01:20:56 |
| 合計ジャッジ時間 | 2,590 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
#define int long long
signed main(){
int n;cin>>n;
map<int,int> m;
for(int i=2;i*i<=n;i++){
while(n%i==0){
m[i]++;
n/=i;
}
}
if(n!=1)m[n]++;
int ans=1;
for(auto x:m){
int a=1,sum=1;
rep(i,x.second){
a*=x.first;
sum+=a;
}
ans*=sum;
}
cout<<ans<<endl;
}
/*
N = p^a * q^b * r^c * ...
の約数の和は
(p^0 + p^1 + ... + p^a)(q^0 + q^1 + ... + q^b)(r^0 + r^1 + ... + r^c)...
おまけ
A = x^0 + x^1 + ... + x^n とおく ...①
Ax = x^1 + x^2 + ... + x^(n+1) ...②
② - ①より
A(x-1) = x^(n+1) - x^0
A = (x^(n+1)-1)/(x-1)
この式変形をしても計算量は変わりません
<<これをしたら largeのテストケースでoverflowしました。かなしい
*/
toririm_