Skip to content

Riturao/Chocolate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

import java.util.; import java.io.; import java.lang.*; //This code is generated by Ritu Rao Patibandla

/* Suppose a teacher has chocolate bars in the sizes such that the minwidth and maxwidth and of minheight and maxheight. The teacher has to distribute the chocolates to the students only when the chocolate is a square,that means suppose if she has the chocolate bars of minwidth=2 and maxwidth=4 and minheight=3 and maxheight=6, then she has bars of sizes (2,3),(2,4),(2,5),(2,6),(3,3),(3,4),(3,5),(3,6),(4,3),(4,4),(4,5),(4,6); she can give the chocolate to a student if the width and height of the chocolate is same, and if not then she will break the chocolate to make it square such as (2,3) can be broken down into (2,2) and(2,1) and later (2,1)will be broken down into (1,1) and (1,1).

eg. input 1 3 1 2 output 12 how many kids will get the chocolate for given input? */ class Chocolate { public static void main(String args[]) { int i,j,k,l,x,y,ccount=0; Scanner a=new Scanner(System.in); Scanner b= new Scanner(System.in); Scanner c= new Scanner(System.in); Scanner d= new Scanner(System.in); i=a.nextInt(); j=b.nextInt(); k=c.nextInt(); l=d.nextInt();

for (x=i;x<=j;x++){
  for (y=k;y<=l;y++){
   ccount=small(x,y,ccount); 
  }
  }
System.out.println(ccount);

}

public static int small(int a,int b,int c){ int min,max,count=c,a11; if(a==b){ count=count+1; } else if(a!=b) { min=Math.min(a,b); max=Math.max(a,b); a11=max-min; count=small(min,min,count); count=small(a11,min,count); } return count; } }