hdu 2504 java 为什么是WA? 10
题目网址:【http://acm.hdu.edu.cn/showproblem.php?pid=2504】importjava.util.*;publicclassMai...
题目网址:【http://acm.hdu.edu.cn/showproblem.php?pid=2504】
import java.util.*;
public class Main{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T-- != 0){
int a = in.nextInt();
int b = in.nextInt();
int c = 0;
if(a<b){
int t = b;
b = a;
a = t;
}
for(int i=2;i<a/b;i++){
if(a/b%i != 0){
c = i;
break;
}
}
System.out.println(c*b);
}
}
}
求解答谢谢~ 展开
import java.util.*;
public class Main{
public static void main(String []args){
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T-- != 0){
int a = in.nextInt();
int b = in.nextInt();
int c = 0;
if(a<b){
int t = b;
b = a;
a = t;
}
for(int i=2;i<a/b;i++){
if(a/b%i != 0){
c = i;
break;
}
}
System.out.println(c*b);
}
}
}
求解答谢谢~ 展开
展开全部
哪里有那么复杂啊。通过数学知识分析下就知道c的最小值就是2*b.
public static void main(String []args){
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T-- != 0){
try{
int a = in.nextInt();
int b = in.nextInt();
}catch(Exception e){
System.out.println("输入有误!");
return;
}
if(b==0){
System.out.println("参数错误!");
}
int c = 0;
if(a<b){
int t = b;
b = a;
a = t;
}
System.out.println(2*b);
}
}
public static void main(String []args){
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T-- != 0){
try{
int a = in.nextInt();
int b = in.nextInt();
}catch(Exception e){
System.out.println("输入有误!");
return;
}
if(b==0){
System.out.println("参数错误!");
}
int c = 0;
if(a<b){
int t = b;
b = a;
a = t;
}
System.out.println(2*b);
}
}
追问
你这里面全是错误我也是醉了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询