-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathpronicnumber.go
More file actions
23 lines (20 loc) · 684 Bytes
/
pronicnumber.go
File metadata and controls
23 lines (20 loc) · 684 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// pronicnumber.go
// description: Returns true if the number is pronic and false otherwise
// details:
// Pronic number: For any integer n, if there exists integer m
// such that n = m * (m + 1) then n is called a pronic number.
// wikipedia: https://en.wikipedia.org/wiki/Pronic_number
// time complexity: O(1)
// space complexity: O(1)
// author: Akshay Dubey (https://github.com/itsAkshayDubey)
// see pronicnumber_test.go
package math
import "math"
// PronicNumber returns true if argument passed to the function is pronic and false otherwise.
func PronicNumber(n int) bool {
if n < 0 || n%2 == 1 {
return false
}
x := int(math.Sqrt(float64(n)))
return n == x*(x+1)
}