## Codeforces #47, Problem E

``````1:  import java.io.BufferedReader;
2:  import java.io.IOException;
4:  import java.util.HashMap;
5:  public class Main {
6:       public static void main(String[] args) throws IOException {
9:            String var[]=ans.split(" ");
10:            HashMap<Integer, Double> val=new HashMap<Integer, Double>();
11:            double dx=0;
12:            int cnt=0;
13:            double rt1=0;
14:            double rt2=0;
15:            val.put(null, (double)1);
16:            val.put(null, (double) 2);
17:            for(double i=1;i<=Integer.parseInt(var[0]);i++){
18:                 for(double j=1;j<=Integer.parseInt(var[1]);j++){
19:                      dx= Math.pow(2*i, 2)-(4*j);
20:                      if(dx>0){
21:                           rt1= (((-2*i)+ Math.sqrt(dx)))/2;
22:                           rt2= (((-2*i) - Math.sqrt(dx)))/2;
23:                           if(val.get(cnt)==null){
24:                                cnt=cnt+1;
25:                                val.put(cnt,(double)rt2);
26:                           }
27:                           if(val.get(cnt)==null){
28:                                cnt=cnt+1;
29:                                val.put(cnt,(double)rt1);
30:                           }
31:                           if(val.containsValue(rt1) &&val.containsValue(rt2)){
32:                           }else if(val.containsValue(rt1)){
33:                                cnt=cnt+1;
34:                                val.put(cnt,(double)rt2);
35:                           }else if(val.containsValue(rt2)){
36:                                cnt=cnt+1;
37:                                val.put(cnt,(double)rt1);
38:                           }else{
39:                                cnt=cnt+2;
40:                           val.put(cnt,(double)rt1);
41:                           val.put(cnt,(double)rt2);
42:                           }
43:                      }else if(dx==0){
44:                           rt1=(double) ((-2*i)/2);
45:                           if(val.get(1)==null){
46:                                cnt=cnt+1;
47:                                val.put(cnt,(double) rt1);
48:                           }
49:                           if(val.containsValue(rt1)){
50:                           }else{
51:                                cnt=cnt+1;
52:                                val.put(cnt,(double)rt1);
53:                           }
54:                      }
55:                 }
56:            }
57:            System.out.println(cnt);
58:       }
59:  }
``````