zoukankan      html  css  js  c++  java
  • 华东交通大学2017年ACM“双基”程序设计竞赛 1010

    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

    解法:当然是暴力跑出结果啦
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int main(){
     4     string s;
     5     while(cin>>s){
     6         int cnt=0;
     7         long long n=0;
     8         if(s.length()>=11){
     9             cout<<"QAQ"<<endl;
    10         }else{
    11             for(int i=0;i<s.length();i++){
    12                 n*=10;
    13                 n+=s[i]-'0';
    14             }
    15             if(n<4294967296){
    16                 while(n>1){
    17                     cnt++;
    18                     n=sqrt(n);
    19                 }
    20                 cout<<cnt<<endl;
    21             }else{
    22                 cout<<"QAQ"<<endl;
    23             }
    24         }
    25     }
    26 }
    1 import math
    2 for i in range(4011110000,5011110000):
    3     num =math.sqrt(math.sqrt(math.sqrt(math.sqrt(math.sqrt(i)))))
    4     if num >=2:  # 确定第一个因子
    5         print(i)
    6         break
  • 相关阅读:
    观察者模式
    Java中关于HashMap源码的研究
    抽象工厂模式
    适配器模式
    oracle创建表空间并赋予权限
    外观模式
    oracle中循环读出一个表的信息插入到另外一个表中
    javaScript对金额处理的方式
    装饰器模式
    建造者模式
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7857560.html
Copyright © 2011-2022 走看看