代码:
import java.util.Scanner;public class Hankson的趣味题 { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] data=new int[n]; for (int i = 0; i < data.length; i++) { int max=0; int a0=sc.nextInt(); if(a0>max)max=a0; int a1=sc.nextInt(); if(a1>max)max=a1; int b0=sc.nextInt(); if(b0>max)max=b0; int b1=sc.nextInt(); if(b1>max)max=b1; data[i]=getCount(a0,a1,b0,b1,max); } for (int i = 0; i < data.length; i++) { System.out.PRintln(data[i]); } } private static int getCount(int a0, int a1, int b0, int b1,int max) { int count=0; for (int i = 1; i <= max; i++) { if(gcd(i,a0)==a1&&i*b0/gcd(i,b0)==b1) count++; } return count; } private static int gcd(int i, int j) { if(i%j==0) return j; return gcd(j,i%j); }}
新闻热点
疑难解答