//1018
//思路:求这个阶乘结果的位数,因为是阶乘结果(乘积)取对数,就相当于对每个对数求和
/* 123456=1.23456*10^5;
log10(123456) = 5.09151;
log10(1.23456 * 10 ^ 5) = log10(1.23456) + log10(10 ^ 5) = 0.09151 + 5;
故int(log10(n)) + 1 就是n的位数*/
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int n, test, i, ans;
double t;
cin >> test;
while (test--)
{
cin >> n;
t = 0;
//乘积取对数相当于对数求和
for ( i = 2; i <= n; i++)
{
t += log10(i*1.0);
}
ans = int(t) + 1;
cout << ans << endl;
}
return 0;
}
//1019
//思路:先求出其最大公约数,再根据lcm=a*b/gcd求得最小公倍数
#include<iostream>
#include<cmath>
using namespace std;
//递归求最大公约数
int gcd(int a ,int b)
{
if (a%b==0)
{
return b;
}
return gcd(b, a%b);
}
//两数之积除以gcd就是lcm
int lcm(int a, int b)
{
int temp;
//确保a比b小
if (a>b)
{
temp = a;
a = b;
b = temp;
}
int g = gcd(a, b);
return (a*b / g);
}
int main()
{
int test;
cin >> test;
int n;
int i;
int m;
while (test--)
{
cin >> n;
cin >> m;
int l = lcm(1, m);
for (i = 1; i < n; i++)
{
cin >> m;
l = lcm(l, m);
}
cout << l << endl;
}
return 0;
}
参考博客:https://www.cnblogs.com/zhourongqing/archive/2012/05/07/2487430.html
原文地址:https://www.cnblogs.com/BlueBlue-Sky/p/8530246.html