MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Twin

Function Twin

math/prime/twin.go:17–22  ·  view source on GitHub ↗

This function returns twin prime for given number returns (n + 2) if both n and (n + 2) are prime -1 otherwise

(n int)

Source from the content-addressed store, hash-verified

15// returns (n + 2) if both n and (n + 2) are prime
16// -1 otherwise
17func Twin(n int) (int, bool) {
18 if OptimizedTrialDivision(int64(n)) && OptimizedTrialDivision(int64(n+2)) {
19 return n + 2, true
20 }
21 return -1, false
22}

Callers 2

TestTwinFunction · 0.92
BenchmarkTwinFunction · 0.92

Calls 1

OptimizedTrialDivisionFunction · 0.85

Tested by 2

TestTwinFunction · 0.74
BenchmarkTwinFunction · 0.74