[转载]Sum of Divisors     (与求约数个数相关)

霸气。。写了个很慢的,直接没跑出来。。
Sum of Divisors
Time Limit: 1000MSMemory Limit: 32768K64bit IO Format: %lld & %llu

[Submit]   [Go Back]   [Status]

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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值