Jacob_Thomas

Untitled

Jun 20th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.*;
  3. class totalmultiples2
  4. {
  5.     public static void main(String args[])throws IOException
  6.     {
  7.         try
  8.         {
  9.             Scanner sc=new Scanner(System.in);
  10.             long a=sc.nextLong();
  11.             long b=sc.nextLong();
  12.             int counter=0;
  13.             long max=a<b?a:b;
  14.             long sqr=a<b?(long)Math.sqrt(a):(long)Math.sqrt(b);
  15.             for(long x=1;x<=sqr;x++)
  16.             {
  17.                 if(max%x==0)
  18.                 {
  19.                     if(x==1)
  20.                     counter+=1;
  21.                     else
  22.                     {
  23.                         if(a%x==0&&b%x==0)
  24.                         counter+=1;
  25.                             long sec=a/x;
  26.                             if(a%sec==0&&b%sec==0)
  27.                             counter+=1;
  28.                        
  29.                     }
  30.                 }
  31.             }
  32.             System.out.println(counter);
  33.            
  34.        
  35.         }
  36.         catch(Exception e)
  37.         {
  38.             System.out.println("ERROR");
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment