首页 技术 正文
技术 2022年11月20日
0 收藏 454 点赞 2,548 浏览 819 个字

资源限制时间限制:1.0s   内存限制:256.0MB


问题描述

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

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

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

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


输入格式输入包含三个正整数a, b, c,表示每个组正在加班的人数,用空格分开(a,b,c<30)输出格式输出一个正整数,表示每袋核桃的数量。


样例输入12 4 5样例输出120


样例输入23 1 1样例输出23


 1 import java.util.Scanner;
2
3 public class Main {
4 public static void main(String args[]){
5 Scanner in=new Scanner(System.in);
6 int a,b,c;
7 a=in.nextInt();b=in.nextInt();c=in.nextInt();
8 int d=lcm(a,b);
9 int ans=lcm(c,d);
10 System.out.println(ans);
11 }
12 public static int gcd(int a,int b){
13 int temp;
14 if (a<b){
15 temp=a;
16 a=b;
17 b=temp;
18 }
19 while (b!=0){
20 temp=a%b;
21 a=b;
22 b=temp;
23 }
24 return a;
25 }
26
27 public static int lcm(int a,int b){
28 int temp_lcm;
29 temp_lcm=a*b/gcd(a,b);
30 return temp_lcm;
31 }
32 }

题解:因为是三个数,所以先调用前面的两个数的最小公倍数(d) 再调方法求出d和最后一个(c)的最小公倍数。

方法:gcd(int a,int b) => 使用辗除法求出最小公约数

方法:lcm(int a,int b) => 求公倍数

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,954
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,479
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,291
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,108
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,740
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,774