Is this $587$ digit number a multiple of $7$?

87 Views Asked by At

Is there any program or formula I can use to find out if this number below with $587$ decimal digits is a multiple of $7$?

30576148829740138953999438154435898092818919944533907506328558978559133324120499819858510061160544485423038309265225641262711922181710849419227945301717887409045108401198337094223287364797822419556232895905120129780873950688569433634916048421351767823038918734482252396717444751003454441061564466523259364390514017386934600569265634819534200864654170662400560775759617256148235309605883714640560228789958485809590774593681062035669045090437411568745546591963643442240406835241222081558413063318123260026420089227327133756040905398490440352160605856566874897425839282123404657432219978117

3

There are 3 best solutions below

1
On

Mathematica shows it is prime in 0.016222 seconds:

Timing[FactorInteger[
  30576148829740138953999438154435898092818919944533907506328558978559\
1333241204998198585100611605444854230383092652256412627119221817108494\
1922794530171788740904510840119833709422328736479782241955623289590512\
0129780873950688569433634916048421351767823038918734482252396717444751\
0034544410615644665232593643905140173869346005692656348195342008646541\
7066240056077575961725614823530960588371464056022878995848580959077459\
3681062035669045090437411568745546591963643442240406835241222081558413\
0633181232600264200892273271337560409053984904403521606058565668748974\
25839282123404657432219978117]]
0
On
def isDivisibleBy7(num) :
 
# If number is negative, make it positive
if num < 0 :
    return isDivisibleBy7( -num )

# Base cases
if( num == 0 or num == 7 ) :
    return True
 
if( num < 10 ) :
    return False
     
# Recur for ( num / 10 - 2 * num % 10 )
return isDivisibleBy7( num / 10 - 2 * ( num - num / 10 * 10 ) )
 

Just run this code and find whether the number is divisible by $7$ or not. In this case the number you said in question is not divisible by $7$. There is no general way to check if such a large number is divisible by $7$.

1
On

To answer your question, there are a number of ways to check whether a certain number is divisible by $7$. However, since your number is fairly large, it would be quite difficult to do this manually and most methods are highly inefficient, so I will be including some Python code that you can use for each method.

Method $1$

As mentioned by Greg Martin in the comments, by splitting the number into groups of $6$ digits (from the right) and adding those groups, the sum is divisible by $7$ if and only if the original number was divisible by $7$.

There are a total of $98$ groups of $6$ digits (with the last group containing $5$ digits) in your number, and the sum of all the groups is $46743415$.

We can apply the same concept again, and we will find that the number is not divisible by $7$.

Code:

group = ''
groups = []
sum = 0

num = 30576148829740138953999438154435898092818919944533907506328558978559133324120499819858510061160544485423038309265225641262711922181710849419227945301717887409045108401198337094223287364797822419556232895905120129780873950688569433634916048421351767823038918734482252396717444751003454441061564466523259364390514017386934600569265634819534200864654170662400560775759617256148235309605883714640560228789958485809590774593681062035669045090437411568745546591963643442240406835241222081558413063318123260026420089227327133756040905398490440352160605856566874897425839282123404657432219978117

for group6 in reversed(str(num)):
    group += group6
    if len(group) == 6:
        groups.append(int(''.join(reversed(group))))
        group = ''
try:
    groups.append(int(''.join(reversed(group))))
except:
    pass

#print(groups) #if you wish to display all the groups

for group6 in groups:
    sum += group6

if sum%7 == 0:
    print('Number is divisible by 7.')
else:
    print('Number is not divisible by 7.')

Method $2$

Multiply the last digit by $2$ and subtract this from the remaining digits. Keep repeating the process to test if a number is divisible by $7$.

Note that this is a highly inefficient method to test if a number is divisible by $7$, especially for larger numbers.

Nevertheless, I have included the code below. The number is not divisible by $7$.

Code:

num = 30576148829740138953999438154435898092818919944533907506328558978559133324120499819858510061160544485423038309265225641262711922181710849419227945301717887409045108401198337094223287364797822419556232895905120129780873950688569433634916048421351767823038918734482252396717444751003454441061564466523259364390514017386934600569265634819534200864654170662400560775759617256148235309605883714640560228789958485809590774593681062035669045090437411568745546591963643442240406835241222081558413063318123260026420089227327133756040905398490440352160605856566874897425839282123404657432219978117

while True:
    last_digit = num%10
    num //= 10
    num -= last_digit * 2
    #print(num) #if you wish to display all the numbers
    if num == 7 or num == 0:
        print('Number is divisible by 7.')
        break
    if num < 0:
        print('Number is not divisible by 7.')    
        break

Method $3$

Multiply the last digit by $5$ and add it to the remaining digits in the number.

Note that this is also another highly inefficient method to test if a number is divisible by $7$, especially for larger numbers. This method is also quite similar to Method $2$.

Nevertheless, I have included the code below. The number is not divisible by $7$.

num = 30576148829740138953999438154435898092818919944533907506328558978559133324120499819858510061160544485423038309265225641262711922181710849419227945301717887409045108401198337094223287364797822419556232895905120129780873950688569433634916048421351767823038918734482252396717444751003454441061564466523259364390514017386934600569265634819534200864654170662400560775759617256148235309605883714640560228789958485809590774593681062035669045090437411568745546591963643442240406835241222081558413063318123260026420089227327133756040905398490440352160605856566874897425839282123404657432219978117

while True:
    last_digit = num%10
    num //= 10
    num += last_digit * 5
    #print(num) #if you wish to display all the numbers
    if num == 7 or num == 49:
        print('Number is divisible by 7.')
        break
    if num < 14:
        print('Number is not divisible by 7.')    
        break

Finally, a few lines of Python code can easily tell you whether a number is divisible by $7$, or any number for that matter.

Code:

num = 30576148829740138953999438154435898092818919944533907506328558978559133324120499819858510061160544485423038309265225641262711922181710849419227945301717887409045108401198337094223287364797822419556232895905120129780873950688569433634916048421351767823038918734482252396717444751003454441061564466523259364390514017386934600569265634819534200864654170662400560775759617256148235309605883714640560228789958485809590774593681062035669045090437411568745546591963643442240406835241222081558413063318123260026420089227327133756040905398490440352160605856566874897425839282123404657432219978117

if num%7 == 0:
    print('Number is divisible by 7.')
else:
    print('Number is not divisible by 7.')

I hope that helps!