Advertisement
Spocoman

13. Prime Pairs

Sep 25th, 2024
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.96 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.     "math"
  6. )
  7.  
  8. func main() {
  9.     var firstStart, secondStart, firstDiff, secondDiff int
  10.     fmt.Scanln(&firstStart)
  11.     fmt.Scanln(&secondStart)
  12.     fmt.Scanln(&firstDiff)
  13.     fmt.Scanln(&secondDiff)
  14.    
  15.     for i := firstStart; i <= firstStart + firstDiff; i++ {
  16.         for j := secondStart; j <= secondStart + secondDiff; j++ {
  17.             var isFirstPrime = true
  18.             var isSecondPrime = true
  19.             for k := 2; k <= int(math.Sqrt(float64(i))); k++ {
  20.                 if i % k == 0 {
  21.                     isFirstPrime = false
  22.                     break
  23.                 }
  24.             }
  25.             for k := 2; k <= int(math.Sqrt(float64(j))); k++ {
  26.                 if j % k == 0 {
  27.                     isSecondPrime = false
  28.                     break
  29.                 }
  30.             }
  31.             if isFirstPrime && isSecondPrime {
  32.                 fmt.Printf("%d%d\n", i, j)
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement