c语言核桃的数量--程序设计,核桃的数量

小张是软件项目经理,他带领3个开发组。工期紧,今天都在加班呢。为鼓舞士气,小张打算给每个组发一袋核桃(据传言能补脑)。他的要求是:

1. 各组的核桃数量必须相同

2. 各组内必须能平分核桃(当然是不能打碎的)

3. 尽量提供满足1,2条件的最小数量(节约闹革命嘛)

程序从标准输入读入:

a b c

a,b,c都是正整数,表示每个组正在加班的人数,用空格分开(a,b,c<30)

程序输出:

一个正整数,表示每袋核桃的数量。

例如:

用户输入:

2 4 5

程序输出:

20

再例如:

用户输入:

3 1 1

程序输出:

3

这道题的说白了就是求最小公倍数

import java.util.Scanner;

public class TestArray {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int a = sc.nextInt();

int b = sc.nextInt();

int c = sc.nextInt();

System.out.println(LCM(LCM(a, b), c));

}

//求出最小公倍数

public static int LCM(int number1, int number2) {

int hello = 0;

int product = number1 * number2;

// 如果number1

if (number1 < number2) {

hello = number1;

number1 = number2;

number2 = hello;

}

while (number2 != 0) {

hello = number1 % number2;

number1 = number2;

number2 = hello;

}

return product / number1;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值