核桃的数量

    xiaoxiao2021-03-25  72

    标题:核桃的数量

    小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是: 1. 各组的核桃数量必须相同 2. 各组内必须能平分核桃(当然是不能打碎的) 3. 尽量提供满足1,2条件的最小数量(节约闹革命嘛)

    程序从标准输入读入: a b c a,b,c都是正整数,表示每个组正在加班的人数,用空格分开(a,b,c<30)

    程序输出: 一个正整数,表示每袋核桃的数量。

    例如: 用户输入: 2 4 5

    程序输出: 20

    再例如: 用户输入: 3 1 1

    程序输出: 3

    资源约定: 峰值内存消耗(含虚拟机) < 64M CPU消耗 < 1000ms

    请严格按要求输出,不要画蛇添足地打印类似:“请您输入…” 的多余内容。

    所有代码放在同一个源文件中,调试通过后,拷贝提交该源码。

    public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String string[] =str.split(" "); String sa =string[0]; String sb =string[1]; String sd =string[2]; int m = Integer.valueOf(sa); int n = Integer.valueOf(sb); int w = Integer.valueOf(sd); int i,j,k,f; i=m; j=n; k =i*j/ gongyue(m, n); i=k; j =w; f = i*j/gongyue(k, w); System.out.println(f); } public static int gongyue(int a, int b) { /*while (a != b) { if (a <b) { a = a/b; }else { b= b /a; } }*/ int i=0; if (a <b) { int c = a; a=b; b=c; } if (b==0) { i=a; } else { return gongyue(b,a%b); } return i; } }
    转载请注明原文地址: https://ju.6miu.com/read-39826.html

    最新回复(0)