題目
判斷兩者有沒有互質
package ch6;
import java.io.*;
public class ch6_11_3
{
public static void main(String awgs[])throws IOException
{
int i,a,b,a1,b1,z=0;
String sa,sb;
InputStreamReader in=new InputStreamReader(System.in);
BufferedReader buf=new BufferedReader(in);
sa=buf.readLine();
a=Integer.parseInt(sa);
sb=buf.readLine();
b=Integer.parseInt(sb);
for (i=2;i<=a;i++)
{
a1=a%i;
b1=b%i;
if(a1==0&b1==0)
{
System.out.println(i+"是兩者的共同質因數");
z=z+1;
}
}
if(z==0)
System.out.println(a+","+b+"兩者互質");
}
}
=============
99
100
99,100兩者互質
留言列表