题解 | #求最小公倍数#

求最小公倍数

https://www.nowcoder.com/practice/22948c2cad484e0291350abad86136c3

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.Arrays.*;
import static java.util.stream.Stream.*;


public class Main {
    public static void main(String[] args) throws IOException {

        testTh();
    }
    private static void testTh() throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String str;
        StringBuilder sb=new StringBuilder();
        while ((str=bf.readLine())!=null){
            String[] s = str.split(" ");
            int a = Integer.parseInt(s[0]);
            int b = Integer.parseInt(s[1]);
            int flag=0;
            if (a%b==0){
                flag=1;
                System.out.println(a);
            }
            else if (b%a==0){
                flag=1;
                System.out.println(b);
            }
            if (flag==0){
                if (a*b/2%a==0&&a*b/2%b==0) System.out.println(a*b/2);
                else if (a*b/3%a==0&&a*b/3%b==0) System.out.println(a*b/3);
                else System.out.println(a*b);
            }
        }

        }


    }

全部评论

相关推荐

2024-11-19 12:59
门头沟学院 测试开发
流浪offer计划:比起假惺惺的人才库,这才是冬日里的温暖
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务