SHARE
TWEET

Untitled

a guest Sep 17th, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Foundation
  2.  
  3. func listSquared(_ m: Int, _ n: Int) -> [(Int, Int)] {
  4.     var buff: [Int] = []
  5.     var out: [(Int, Int)] = []
  6.    
  7.     for x in m...n {
  8.       buff.removeAll()
  9.       let sqr = sqrt(Double(x))
  10.       for i in 2..<Int(sqr)+1 {
  11.         if x % i == 0 {
  12.             print(i)
  13.             if i != (x/i) {
  14.                 buff.append((x/i)*(x/i))
  15.             }
  16.         }
  17.       }  
  18.      
  19.       let sum = buff.reduce(0, +)
  20.       let isPrime = sum > 1 && !(2..<sum).contains { sum % $0 == 0 }
  21.       if isPrime {
  22.         out.append((x, sum))
  23.       }
  24.    
  25.    
  26.     }
  27.     return out
  28. }
  29.  
  30. listSquared(1, 250)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top