View Code of Problem 102

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			if(x == y) {
				System.out.println(1);
				continue;
			}
			if(y%x != 0) {
				System.out.println(0);
				continue;
			}
			int cheng = x*y;
			int count = 0;
			int s=(int)Math.sqrt(cheng);
			for(int i=x; i<=s; i++) {
				if((cheng % i == 0) && yinshu(cheng/i,i) == x) {
					count ++;
				}
			}
			count *= 2;
			System.out.println(count);
			
		}
	}

	public static int yinshu(int a, int b) {
		// TODO Auto-generated method stub
		int c = a % b;
		while(c != 0) {
			a = b; 
			b = c;
			c = a % b;
		}
		return b;
	}
	
}
/*
Main.java:3: error: cannot find symbol
		Scanner scanner = new Scanner(System.in);
		^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
		Scanner scanner = new Scanner(System.in);
		                      ^
  symbol:   class Scanner
  location: class Main
2 errors
*/

Double click to view unformatted code.


Back to problem 102