霸气。。写了个很慢的,直接没跑出来。。
The input contains several cases, each has a single integer m on a seperate line. All input data fit in a signed 32-bit integer.
The answer for each case should be printed on a seperate line.
1
3392927
3392928
78499
999999
1000000
原文地址:Sum of Divisors (与求约数个数相关)
作者:一直很安静
Sum of Divisors
Time Limit: 1000MS | Memory Limit: 32768K | 64bit IO Format: %lld & %llu |
Description
For an integer n, define f(n) to be the sum of its proper divisors (the divisors excluding the number itself), f is called the restricted divisor function.
Given an integer m. Find how many integers n between 1 and 1000000 (inclusively) has f(n)<=m.
Input
The input contains several cases, each has a single integer m on a seperate line. All input data fit in a signed 32-bit integer.
Output
The answer for each case should be printed on a seperate line.
Sample Input
1
3392927
3392928
Sample Output
78499
999999
1000000
题意:
输入一个数m,求在1到10000000之间,约数个数f(n)小于等于m的个数,保存在数组a里,再将其从小到大排序,
由输入输出范例可知本题可先求出m在1--3392928之间所对应的f(n)的值,及m==1时对应f(1),
以此类推下去....f(m)对应a[m]
#include<iostream>
#include<algorithm>
using namespace std;
int a[1000001]={0};
int b[3400000]={0};
int main()
{
int n,m,i,j,k,sum;
for(i=1;i<=3400000;i++)
for(j=2;i*j<1000001;j++)
{
a[i*j]+=i;//精髓,很方便+快速!!!!
}
sort(a,a+1000001);
while(cin>>m)
{
for(i=2;i<=1000001;i++)
{
if(m>=3392928)
{ cout<<"1000000"<<endl;
break;}
if(a[i]>m)
{
cout<<i-1<<endl;
break;
}
}
}
return 0;
}