1~n的最小公倍数(n<=100)
开个质数集合以及他们的计数器
比如72能分成2*2*2*3*3
则对72进行检查时,把质数2的计数器记为3,质数3的奇数器记为2(如果之前比这个新值小的话)
最后造个大数结构,把所有质数位上的计数器次方,全部乘起来
#include <stdio.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long ll;
void multi(ll * a, ll t)
{
ll temp[1000] = { 0 };
for (ll i = 0; i <= a[999]; ++i)
{
a[i] *= t;
a[i] += temp[i];
if (a[i] > 100000000)
{
temp[i + 1] = a[i] / 100000000;
a[i] %= 100000000;
}
}
if (temp[a[999] + 1])
{
a[a[999] + 1] = temp[a[999] + 1];
++a[999];
}
}
ll a[1000] = { 0 };
int main()
{
a[0] = 1;
ll prime[25] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 }, b[100] = { 0 }, pos = 0, n;
scanf("%lld", &n);
for (ll i = 2; i <= n; ++i)
{
ll temp = i;
pos = 0;
while (temp > 1)
{
ll powtemp = 0;
while (temp % prime[pos] == 0)
{
temp /= prime[pos];
++powtemp;
}
if (powtemp > b[pos])
b[pos] = powtemp;
++pos;
}
}
ll mul = 1;
pos = 24;
while (pos >= 0)
{
if (b[pos] == 0)
{
--pos;
continue;
}
ll temp = mul * prime[pos];
--b[pos];
if (temp < 100000000)
{
mul = temp;
}
else
{
multi(a, mul);
mul = prime[pos];
}
}
multi(a, mul);
printf("%lld", a[a[999]]);
if (a[999])
{
for (ll i = a[999] - 1; i >= 0; --i)
printf("%08lld", a[i]);
}
printf("\n");
}