Created
April 17, 2020 17:20
-
-
Save sudoankit/7a5dfa8dd0e0ac46e481648ff630b6f7 to your computer and use it in GitHub Desktop.
Lazy caterer's sequence, Timus Online Judge: 1209 - 1, 10, 100, 1000...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cstdio> | |
#include<cmath> | |
using namespace std; | |
int main(){ | |
long n; | |
cin >> n; | |
while(n--){ | |
long double p, test; | |
cin >> p; | |
test = sqrt(8*p - 7); | |
if (test - floor(test) == 0) | |
cout << 1 << ' '; | |
else | |
cout << 0 << ' '; | |
} | |
} | |
// This actually is disguised as a problem which uses the Lazy caterer's sequence -- | |
// central polygonal numbers, describes the maximum number of pieces of a disk | |
// (a pancake or pizza is usually used to describe the situation) that can be made | |
// with a given number of straight cuts. https://en.wikipedia.org/wiki/Lazy_caterer%27s_sequence | |
// 1 + n(n+1)/2 = input (p) | |
// solving if sqrt(8p-7) is perfect it's true, else false. | |
// AC in 1 try. |
Solve for
Got it. Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why - 7?