SHARE
TWEET

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

a guest Mar 12th, 2014 115 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top