• Loading...

Problem 9: Sum of divisors

Points

Small Case: 5 Answer: 1355

Large Case: 15 Answer: 4001488450455

Consider the number 4. It's divisors are 1,2 and 4. The sum of it's divisors is 7.

Now all numbers less than or equal to 7 can be respresented as a sum of distinct divisors of 4.


1 = 1
2 = 2.
3 = 1 + 2
4 = 4
5 = 1 + 4
6 = 2 + 4
7 = 1 + 2 + 4.

For 10, the divisors are 1,2,5 and 10 and the sum of it's divisors is 18. But 14 cannot be represented as a sum of distinct divisors of 10.

Find the sum of all numbers M less than or equal to N such that every number less than or equal to sum of it's divisors can be represented as a sum of distinct divisors of M.

Small Case: N=100
Large Case: N=10000000

Solution:

Practical Numbers are those numbers n such that every k <= sigma(n) is a sum of distinct divisors of n.It is also defined by as:
A number n = p1e1*p2e2*....*pkek with n>1 and primes p1<p2<...<pk is practical if and only if p1 = 2 and for every i from 2 to k

Reload Page

Reference:N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995[A005153]

Code:



#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <iostream>
using namespace std;
#include<vector>
#include <math.h>
 
int primes[100000];
int ctr=0;
 
void sieve(int N)
{
     int M=(N-1)/2;
     int x=(floor(sqrt(N))-1)/2,i,j;
     vector<bool> S(M+1,0);
     primes[ctr++]=2;
     for (i=1;i<=x;i++)
         if (!S[i])
            for (j=2*i*(i+1);j<=M;j+=(2*i+1))
                S[j]=1;
 
     for (i=1;i<=M;i++)
         if (!S[i])
            primes[ctr++]=(2*i+1);
 
}
 
bool ispractical(int n)
{
    if (n%2==1)
            return 0;
    int c=0,j=n;
    long long sigma=1;
    while (j>1 && primes[c]*primes[c]<=n)
    {
        if (j%primes[c]==0)
        {
            int k=primes[c];                        
            if (k>sigma+1)
                    return 0;
            int m=k;
            while (j%k==0)
            {
                    m*=k;
                    j/=k;
            }
            sigma=sigma*((m-1)/(k-1));
        }
        c++;
    }
    if (j!=1)
        if (j>sigma+1)
                return 0;
    return 1; 
}
 

int main()
{ 
 
    int i,c=0,m;
    sieve(10000);
	long long max=10000000;
    long long sum=1;
    for (i=2;i<=max;i+=2)
    {
        if(ispractical(i))
        {
           sum+=i;
        }
    }
    printf("%lld\n",sum);
    return 0;
}

Submit your solution

You need to be logged in to submit a solution.

discussions


aropanvalid
Q:1 is ok?
A:yes , 1 also satisfies the criteria.

post a question

Loading...

Problem 1
Problem 2
Problem 3
Problem 4
Problem 5 (bonus) Expired
Problem 1
Problem 2
Problem 3
Problem 4 (bonus) Expired
Top Scorers
rng_58 235
Anton_Lunyov 225
tourist 190
Silence 180
cedricl2 175
cgy4ever 175
DrKorbin 165
Koen 155
bbbasic 150
lunae_2 150
Submissions
Problem 1
10 pt
not submitted
98
submissions

19
correct (19 %)



25 pt
not submitted
2
submissions

1
correct (50 %)


Problem 2
5 pt
not submitted
95
submissions

38
correct (40 %)



10 pt
not submitted
19
submissions

15
correct (78 %)


Problem 3
5 pt
not submitted
153
submissions

117
correct (76 %)



15 pt
not submitted
44
submissions

25
correct (56 %)


Problem 4
10 pt
not submitted
152
submissions

54
correct (35 %)



15 pt
not submitted
23
submissions

10
correct (43 %)


Problem 5
10 pt
not submitted
36
submissions

28
correct (77 %)



20 pt
not submitted
6
submissions

2
correct (33 %)


Problem 6
5 pt
not submitted
41
submissions

29
correct (70 %)



10 pt
not submitted
15
submissions

14
correct (93 %)


Problem 7
5 pt
not submitted
38
submissions

17
correct (44 %)



10 pt
not submitted
16
submissions

15
correct (93 %)


Problem 8
5 pt
not submitted
127
submissions

104
correct (81 %)



15 pt
not submitted
47
submissions

34
correct (72 %)


Problem 9
5 pt
not submitted
86
submissions

35
correct (40 %)



15 pt
not submitted
16
submissions

15
correct (93 %)


Problem 10
5 pt
not submitted
45
submissions

23
correct (51 %)



15 pt
not submitted
15
submissions

14
correct (93 %)


Problem 11
5 pt
not submitted
81
submissions

27
correct (33 %)



15 pt
not submitted
8
submissions

3
correct (37 %)


Problem 12
5 pt
not submitted
104
submissions

88
correct (84 %)



10 pt
not submitted
31
submissions

21
correct (67 %)