Pizza Problem

13 Jul, 2021
Given an integer N and a pizza which can be cut into pieces, each cut should be a straight line going from the center of the pizza to its border. Also, the angle between any two cuts must be a positive integer. Two pieces are equal if their appropriate angles are equal. The given pizza can be cut in following three ways:  
Cut the pizza into N equal pieces.Cut the pizza into N pieces of any size.Cut the pizza into N pieces such that no two of them are equal.
Cut the pizza into N equal pieces.
Cut the pizza into N pieces of any size.
Cut the pizza into N pieces such that no two of them are equal.
The task is to find if it is possible to cut the pizza in the above ways for a given value of N. Print 1 if possible else 0 for all the cases i.e. print 111 if all the cases are possible.Examples:  
Input: N = 4 Output: 1 1 1 Case 1: All four pieces can have angle = 90 Case 2: Same cut as Case 1 Case 3: 1, 2, 3 and 354 are the respective angles of the four pieces cut.Input: N = 7 Output: 0 1 1  
 
Approach:  
Case 1 will only be possible if 360 is divisible by N.
For case 2 to be possible, N must be ≤ 360.
An ideal solution for case 3 would be to choose pieces in such a way that the angles they form are 1, 2, 3, ... respectively. So, in order for this case to be possible, (N * (N + 1)) / 2 must be ≤ 360.
Below is the implementation of the above approach:  
C++
Java
Python3
C#
PHP
Javascript
// C++ implementation of the approach#include <iostream>using namespace std; // Function to check if it is possible// to cut the pizza in the given wayvoid cutPizza(int n){    // Case 1    cout << (360 % n == 0) ? "1" : "0";     // Case 2    cout << (n <= 360) ? "1" : "0";     // Case 3    cout << (((n * (n + 1)) / 2) <= 360) ? "1" : "0";} // Driver codeint main(){    int n = 7;    cutPizza(n);     return 0;}
// Java implementation of the approachclass GFG{ // Function to check if it is possible// to cut the pizza in the given waystatic void cutPizza(int n){    // Case 1    System.out.print( (360 % n == 0) ? "1" : "0");     // Case 2    System.out.print( (n <= 360) ? "1" : "0");     // Case 3    System.out.print( (((n * (n + 1)) / 2) <= 360) ? "1" : "0");} // Driver codepublic static void main(String args[]){    int n = 7;    cutPizza(n);}} // This code is contributed by Arnab Kundu
# Python3 implementation of the approach # Function to check if it is possible# to cut the pizza in the given waydef cutPizza(n):     # Case 1    if(360 % n == 0):        print("1", end = "")    else:        print("0", end = "");     # Case 2    if(n <= 360):        print("1", end = "")    else:        print("0", end = "");     # Case 3    if(((n * (n + 1)) / 2) <= 360):        print("1", end = "")    else:        print("0", end = "");  # Driver coden = 7;cutPizza(n); # This code is contributed# by Akanksha Rai
// C# implementation of the approachusing System; class GFG{ // Function to check if it is possible// to cut the pizza in the given waystatic void cutPizza(int n){    // Case 1    Console.Write((360 % n == 0) ? "1" : "0");     // Case 2    Console.Write((n <= 360) ? "1" : "0");     // Case 3    Console.Write((((n * (n + 1)) / 2) <= 360) ? "1" : "0");} // Driver codepublic static void Main(String []args){    int n = 7;    cutPizza(n);}} // This code is contributed by Arnab Kundu
<?php// PHP implementation of the approach // Function to check if it is possible// to cut the pizza in the given wayfunction cutPizza($n){    // Case 1    echo (360 % $n == 0) ? "1" : "0";     // Case 2    echo ($n <= 360) ? "1" : "0";     // Case 3    echo ((($n * ($n + 1)) / 2) <= 360) ? "1" : "0";} // Driver code$n = 7;cutPizza($n); // This code is contributed// by Akanksha Rai?>
<script>// Javascript implementation of the approach // Function to check if it is possible// to cut the pizza in the given wayfunction cutPizza(n){    // Case 1    document.write( (360 % n == 0) ? "1" : "0");       // Case 2    document.write( (n <= 360) ? "1" : "0");       // Case 3    document.write( (((n * (n + 1)) / 2) <= 360) ? "1" : "0");} // Driver codelet n = 7;cutPizza(n); // This code is contributed by avanitrachhadiya2155</script>
011
 
andrew1234
Akanksha_Rai
avanitrachhadiya2155
programming-puzzle
C++ Programs
School Programming
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Shallow Copy and Deep Copy in C++
C++ Program to check if a given String is Palindrome or not
C++ Program for QuickSort
delete keyword in C++
C Program to Swap two Numbers
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Introduction To PYTHON
Interfaces in Java