Problem Description
定义操作:将数 n 变为 f(n) = floor(sqrt(n))。即对一个数开平方后,再向下取整。
如对 2 进行一次操作,开平方再向下取整, 1.414213562..... = 1 , 即变为了 1 。
现在给出一个数 n,如果能在 5 次操作内把 n 变为 1,则输出操作次数;如果则超过5次输出"QAQ"。
数据范围:
1<= n <= 10^100
如对 2 进行一次操作,开平方再向下取整, 1.414213562..... = 1 , 即变为了 1 。
现在给出一个数 n,如果能在 5 次操作内把 n 变为 1,则输出操作次数;如果则超过5次输出"QAQ"。
数据范围:
1<= n <= 10^100
Input
多组输入,每行输入一个数 n。
Output
每组数据输出要多少次操作,或者输出"QAQ"
Sample Input
233
233333333333333333333333333333333333333333333333333333333
Sample Output
3
QAQ 解法:当然是暴力跑出结果啦
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
while(cin>>s){
int cnt=;
long long n=;
if(s.length()>=){
cout<<"QAQ"<<endl;
}else{
for(int i=;i<s.length();i++){
n*=;
n+=s[i]-'';
}
if(n<){
while(n>){
cnt++;
n=sqrt(n);
}
cout<<cnt<<endl;
}else{
cout<<"QAQ"<<endl;
}
}
}
}
import math
for i in range(4011110000,5011110000):
num =math.sqrt(math.sqrt(math.sqrt(math.sqrt(math.sqrt(i)))))
if num >=2: # 确定第一个因子
print(i)
break