您的位置:首页 > 其它

华东交通大学2017年ACM“双基”程序设计竞赛 1010

2017-11-18 18:19 267 查看

Problem Description

定义操作:将数 n 变为 f(n) = floor(sqrt(n))。即对一个数开平方后,再向下取整。
如对 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=0;
long long n=0;
if(s.length()>=11){
cout<<"QAQ"<<endl;
}else{
for(int i=0;i<s.length();i++){
n*=10;
n+=s[i]-'0';
}
if(n<4294967296){
while(n>1){
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: