Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ttt;
- import java.util.*;
- public class cookies {
- static Scanner scan = new Scanner(System.in);
- private static boolean howManyCookies(int p, int c)
- {
- c=c-1;
- if(!(c%p==0)) return false;
- for(int i=0; i<p; i++)
- {
- c=c/p*(p-1)-1;
- if(c%p!=0)
- return false;
- }
- return true;
- }
- public static void main(String[] args)
- {
- int c=1;
- System.out.print("Enter the number of people: ");
- int p = scan.nextInt();
- while(!howManyCookies(p, c))
- c++;
- System.out.print(c);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement