Advertisement
k4u5h4L

Untitled

Jan 21st, 2022 (edited)
717
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def calculateSum(n1, n2):
  2.     flag = 0
  3.     primes = []
  4.     a = n1
  5.     b = n2
  6.     for i in range(a, b):
  7.         if (i == 1):
  8.             continue
  9.  
  10.         flag = 1
  11.          
  12.         for j in range(2, i // 2 + 1):
  13.             if (i % j == 0):
  14.                 flag = 0
  15.                 break
  16.            
  17.         if (flag == 1):
  18.             primes.append(i)
  19.  
  20.     max_val = max(primes)
  21.     if len(primes) == 1:
  22.         return primes[0]
  23.     return sum([abs(max_val - a) for a in primes])
  24.    
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement