Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
这个题用java写怎么在网站上提示编译错误,求大神指教In Reply To:这个题用jaVA Posted by:sdufe20171847126 at 2019-03-04 16:42:12 import java.util.Scanner; public class zuidagongyueshu { // 最大公约数 public static int get_gcd(int n1, int n2) { int gcd = 0; if (n1 < n2) {// 交换n1、n2的值 n1 = n1 + n2; n2 = n1 - n2; n1 = n1 - n2; } if (n1 % n2 == 0) { gcd = n2; } while (n1 % n2 > 0) { n1 = n1 % n2; if (n1 < n2) { n1 = n1 + n2; n2 = n1 - n2; n1 = n1 - n2; } if (n1 % n2 == 0) { gcd = n2; } } return gcd; } // 最小公倍数 public static int get_lcm(int n1, int n2) { return n1 * n2 / get_gcd(n1, n2); } public static void main(String args[]) { Scanner input = new Scanner(System.in); while (input.hasNext()){ int n=input.nextInt(); if (n==0) break; int a = input.nextInt(); if (n==1) { if (a>1000000) { System.out.println("Too much money to pay!"); } else { System.out.println("The CEO must bring " + a + " pounds."); } }else { int ans=a; for (int i=0;i<n-1;i++){ int b=input.nextInt(); ans=get_lcm(ans,b); } if (ans>1000000){ System.out.println("Too much money to pay!"); }else { System.out.println("The CEO must bring " + ans + " pounds."); } } } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator