Should it be in Computer Science?

For every positive integer n n , let d ( n ) \text{d}(n) be the number of positive divisors of n n . Find the sum of all positive integers n n such that n + d ( n ) = ( d ( n ) ) 2 n+\text{d}(n)=(\text{d}(n))^2 .

I'm looking for brilliant solutions. Solutions using programming are also welcome.


Source .


The answer is 1450.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

6 solutions

Patrick Corn
Apr 9, 2015

Solutions to this equation have d ( n ) > n d(n) > \sqrt{n} , so they should be "small." There are some upper bounds on d ( n ) d(n) . One I found here

Link

was d ( n ) n 1.5379 log 2 log log n d(n) \le n^{\frac{1.5379 \log 2}{\log \log n}} and that exponent is less than 1 / 2 1/2 if n 4590 n \ge 4590 . So you should only have to check for n n up to 4589 4589 .

So we have to only check twice of triangular numbers of the form T(sub)2n till n=4589

Vibhu Saksena - 5 years, 9 months ago
Samarpit Swain
Aug 21, 2015

Here's a C++ code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream.h>
#include<conio.h>
void main()
{       unsigned long int num;

         for(unsigned long int x=1;x<=100000;x++)
     {     num=x;
          int dn=1,exp=1,i=2;

      while(i<=num)
      {    if(num%i==0)
          {     exp++;
                  num/=i;
                           }
          else 
           {    dn*=exp;
                  exp=1;
                      i++;
                            }
              }
         dn*=exp;
        if(x+dn==dn*dn)
        cout<<x<<endl;
                   }
getch();
         }

The output comes out to be:

2

56

132

1260

Hence, the sum is 1450 1450

Jubayer Nirjhor
Apr 9, 2015

Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
from math import sqrt

def d(m):
    res = 0
    for i in range (1, int(sqrt(m)) + 1):
        if m % i == 0: res += 2
    if sqrt(m) % 1 == 0: res -= 1
    return res

total = 0

for n in range (1, 10000):
    if n + d(n) == d(n) * d(n):
        total += n
        print n

print "\n", total

Output

1
2
3
4
5
6
2
56
132
1260

1450

Answer: 1450 \fbox{1450}

David Holcer
Apr 8, 2015
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
def factors(n):    
    return set(reduce(list.__add__, 
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

try:
    c=1
    summ=0
    while True:
        if len(factors(c))+c==(len(factors(c)))**2:
            summ+=c
        c+=1
except(KeyboardInterrupt):
    print summ

Not sure if theres infinite n's or not, so added an except so I can exit out of program and view current sum which turns out to be correct, only 4 numbers, (2,56,132,1260) work.

Great :D, I actually did the same solution but in JavaScript, and yes, there are only 4 4 values of n n , but how can we prove it?

Alan Enrique Ontiveros Salazar - 6 years, 2 months ago

Log in to reply

I'm actually curious, are you certain that there are no other n's that satisfy the condition? Or in other words, is 1450 r e a l l y really the answer?

Eric Escober - 6 years, 2 months ago

Log in to reply

Yes, I'm sure because the official solution says that there are only four solutions. But I don't know how to prove that,

Alan Enrique Ontiveros Salazar - 6 years, 2 months ago

Log in to reply

@Alan Enrique Ontiveros Salazar That's reassuring. Thanks! and I guess someone already got the right proof? :)

Eric Escober - 6 years, 1 month ago

L e t : x = a 1 b 1 a 2 b 2 a 3 b 3 a n b n Let: x = { a }_{ 1 }^{ b_{ 1 } } { a }_{ 2 }^{ b_{ 2 }}{ a }_{ 3 }^{ b_{3 }}\dots { a }_{ n }^{ b_{n }} we have d ( x ) = ( b 1 + 1 ) ( b 2 + 1 ) ( b 3 + 1 ) ( b n + 1 ) d(x)=(b_{ 1 }+1)(b_{ 2 }+1)(b_{ 3 }+1)…(b_{ n }+1) we also prove that max of x = 2 5 3 3 5.7 { 2 }^{5 } {3 }^{ 3}{ 5 }.{7} . there are 6.4.2.2 = 96 6.4.2.2 = 96 way possible to try. we find that x = 2 ; 56 ; 132 ; 1260 x = 2; 56; 132; 1260

vu van luan - 6 years, 1 month ago
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<iostream>
using namespace std;

int d(int &n)
{
    int i=1,j=0;
    for(i=1;i<=n;i++)
        {
            if(n%i==0)
                {
                    j++;
                }
        }
        return j;
}
main()

{
    int k=1,s=0;
    for(k=1;k<=10000;k++)
        {
            if(d(k)*d(k)-d(k)==k)
                {
                    s=s+k;
                }
        }
        cout<<s;
}

Gave 1450 1450 . (Luckily!)

Can anyone help me out with large integers?

Kaleab Belete
Feb 10, 2016

A solution that checks for the number of divisors of a very large number can also be easily implemented using some Computer Science algorithms. The divisor function σ ( n ) \sigma (n) can be defined by the mathematical equation,

σ ( n ) = i = 1 r ( a i + 1 ) \sigma (n)=\prod _{ i=1 }^{ r }{ ({ a }_{ i }+1) } _{ } represents the number of occurrences of the i t h { i }^{ th } prime factor of n n and r r denotes the number of distinct prime factors of n n .

Therefore by using this mathematical equation and simple primality testing algorithms , one can easily find the number of divisors of any number quite efficiently.

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...