请看题目,各位大神题目怎么写啊,木有思路求思路和源码⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯⋯
这个是求3个数的最小公倍数吧。
思路我觉得就是求最小公倍数
import java.util.Scanner;
public class Test2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a, b, c;
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
System.out.println(calcWalnutNum(a, b, c));
sc.close();
}
public static int calcWalnutNum(int a, int b, int c) {
return getLCM(getLCM(a, b), c);
}
public static int getLCM(int a, int b) {
int c = a * b;
int r = 0;
if (a < b) {
r = a;
a = b;
b = r;
}
while ((r = a % b) != 0) {
a = b;
b = r;
}
return c / b;
}
}
static void Main(string[] args)
{
int a = Convert.ToInt32(Console.ReadLine());
int b = Convert.ToInt32(Console.ReadLine());
int c = Convert.ToInt32(Console.ReadLine());
int res = m(a, b, c);
Console.WriteLine(res);
Console.ReadKey();
}
static int f(int a, int b)
{
if (a < b)
{
a = a + b;
b = a - b;
a = a - b;
}
return (a % b == 0) ? b : f(a % b, b);
}
static int m(int a, int b)
{
return a * b / f(a, b);
}
static int m(int a, int b, int c)
{
return m(m(a, b), c);
}
求三个数的最小公倍数
自增 i ,当i满足同时整除三个数时,则i为最小公倍数,i最大自增到 30*29*26,不怕超时
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int a=scan.nextInt();
int b=scan.nextInt();
int c=scan.nextInt();
long i=2;
while(i%a!=0||i%b!=0||i%c!=0)
{
i++;
}
System.out.println(i);
}