Advertisement
Guest User

חידת התרמילאים והעוגיות

a guest
Mar 12th, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. package ttt;
  2. import java.util.*;
  3.  
  4. public class cookies {
  5.     static Scanner scan = new Scanner(System.in);
  6.  
  7.     private static boolean howManyCookies(int p, int c)
  8.     {
  9.         c=c-1;
  10.         if(!(c%p==0)) return false;
  11.         for(int i=0; i<p; i++)
  12.         {
  13.             c=c/p*(p-1)-1;
  14.             if(c%p!=0)
  15.                 return false;
  16.         }
  17.         return true;
  18.     }
  19.        
  20.     public static void main(String[] args)
  21.     {
  22.         int c=1;
  23.         System.out.print("Enter the number of people: ");
  24.         int p = scan.nextInt();
  25.         while(!howManyCookies(p, c))
  26.             c++;
  27.         System.out.print(c);
  28.            
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement