题解 AT2523 【[ABC057C] Digits in Multiplication】
这道题目先要学会分析
两个数相乘等于n,位数最好是要一样的,会想到平方根不?
判断平方根是否是整数,是就输出位数,不是从1到平方根慢慢找
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
long long n;
cin >> n;
double f = sqrt(n);
if(f == (int)f)
{
int digit = 0, c = (int)f;
while(c)
{
digit++;
c /= 10;
}
cout << digit << endl;
}
else
{
for(int i = (int)f; i >= 1; i--)
{
if(n % i == 0)
{
int x = (i > n / i ? i : n / i);
int digit = 0;
while(x)
{
digit++;
x /= 10;
}
cout << digit << endl;
break;
}
}
}
return 0;
}

浙公网安备 33010602011771号