地址:http://codeforces.com/contest/1091/problem/D
思路:规律题,比赛时一看就想到是规律题,但是一直没找到规律,看了别人的代码才发现是和前一个值有关
i=1 f[i]=1
i=2 f[i]=2=2!+0 0=2*(1-1)
i=3 f[i]=9=3!+3 3=3*(2-1);
i=4 f[i]=56=4!+32 32=4*(9-1);
i=5 f[i]=395=5!+275 275=5*(56-1);
i=n : f[i]=n!+t t=n*(f[n-1]-1);
Code:
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
const int MAX_N=1e6+5;
int n,m,T;
LL a[MAX_N];
int main()
{
ios::sync_with_stdio(false);
while(cin>>n){
int q=sqrt(n),s=0;
LL t;
for(int i=1,j;i<=q;++i)
if(n%i==0){
t=(n-1)/i;
a[s++]=t*(t+1)/2*i+t+1;
j=n/i;
if(i!=j){
t=(n-1)/j;
a[s++]=t*(t+1)/2*j+t+1;
}
}
sort(a,a+s);
for(int i=0;i<s-1;++i)
cout<<a[i]<<" ";
cout<<a[s-1]<<endl;
}
return 0;
}