蓝桥杯 1446:[蓝桥杯][2013年第四届真题]核桃的数量 Easy only once *最小公倍数问题
基本思路:
题解里面很多人都是枚举方法做的,其实是最小公倍数的求法问题;
关键点:
之前做过相关的数学总结,不再赘述,本质上是先求最大公约数,再借助性质求最小公倍数;
#include<iostream>
#include<stdlib.h>
#include<stdio.h>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
#include<cstring>
using namespace std;
using std::vector;
int find_mn(int a, int b) {
if (b == 0 && a != 0)
return a;
else
return find_mn(b, a%b);
}
int count_ln(int a, int b) {
int n = find_mn(a, b);
if (n == 1)
return a * b;
else
return a * b / n;
}
int main()
{
int a, b, c;
cin >> a >> b >> c;
int temp = 0;
if (a > b)
temp = count_ln(a, b);
else
temp = count_ln(b, a);
if (temp > c)
cout << count_ln(temp, c);
else
cout << count_ln(c, temp);
}

浙公网安备 33010602011771号