forked from love1024/spoj-solution-with-explanation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBEENUMS.cpp
44 lines (36 loc) · 1.01 KB
/
BEENUMS.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
//There is also a O(1) solutions
//which require some calculation to find the
//perfect square
int main() {
//Take the number
int n;
cin>>n;
//Loop until number is not equal to -1
while(n != -1) {
//if the number is 1 simply print Y
if(n == 1)
cout<<"Y"<<endl;
else {
//else find increase the series from 1 until
//we reach equal to given number or greater than that
//series is 1 + 6 + 12 + 18 + 24 ....
//if at last we reach equal to n it means
//it is a beehive number else not
long long i = 1,sum = 1;
while(sum < n) {
sum = sum + 6*i;
i++;
}
//If sum is equal to given number then print Y else N
if(sum == n)
cout<<"Y"<<endl;
else
cout<<"N"<<endl;
}
//Take next number
cin>>n;
}
return 0;
}