B - Increase and Copy
题目描述
思路: 本题首先需要看出最快的方式为:将第一个数不断加一,然后进行拷贝,直至最终所得数字大于等于所给数字。设加了i次,拷贝了j次(即乘了j次),所得的即为(i+1)*(j+1)>=n,要使i+j最小,即使i+1+j+1最小,根据三角不等式,即得出i+1同j+1最接近sqrt(n)时最小。
#include <bits/stdc++.h>
using namespace std
;
int main()
{
int t
;
scanf("%d",&t
);
while(t
--)
{
int n
;
scanf("%d",&n
);
int m
=sqrt(n
);
if(m
*m
==n
)
printf("%d\n",2*m
-2);
else if(m
*(m
+1)>=n
)
printf("%d\n",2*m
-1);
else printf("%d\n",2*m
);
}
return 0;
}
转载请注明原文地址:https://blackberry.8miu.com/read-43743.html