标签:七夕节 center i++ str cstring ios while out main
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn = 5e5+10;
int sum[maxn];
void init()
{
for(int i = 1; i <= maxn/2; i++)
{
for(int j = i + i; j <= maxn; j += i)
sum[j] += i;
}
}
int main(void)
{
init();
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
cout<<sum[n]<<endl;
}
return 0;
}
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(void)
{
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int sum = 0;
for(int i = 1; i*i <= n; i++)
{
if(n%i==0)
{
sum += i;
if(i!=1&&i!=n/i)//注意n是平方数的情况
sum += n/i;
}
}
cout<<sum<<endl;
}
return 0;
}
标签:七夕节 center i++ str cstring ios while out main
原文地址:https://www.cnblogs.com/AC-AC/p/9936462.html