HDU number of qualitative square

Source: Internet
Author: User

Problem Description Xiaoming is naturally sensitive to numbers, and can recite pi 100 when he is 3 years old.

Now, Xiaoming slowly grew up, but still like the numbers, recently, he was fascinated by prime numbers and squares, and he named the square of the prime number as "qualitative square."
Now he's working on the question: what is the closest mass to a positive integer n?

Input data The first line is a positive integer t (t<=20), which indicates that there is a T group of input data.
Next T line, enter a positive integer N (1<=n<=10^8) per line.

Output for each set of data, outputs the nearest mass of N, one row for each set of outputs.

Sample Input2110

Sample Output49

Water out of the national freshman race, I just want to say that at that time test instructions understand wrong.

Yu Min's code:

1#include <iostream>2#include <algorithm>3#include <iomanip>4#include <string>5#include <cstring>6#include <cmath>7 using namespacestd;8 intcmpintx)9 {Ten     if(x==1)return 0; One     Else A     { -          for(intI=2; i<=sqrt (x); i++) -           if(x%i==0)return 0; the     } -     return 1; - } - intMain () + { -     intn,m,i,j,k,t; +Cin>>T; A      while(t--) at     { -Cin>>m; -k=sqrt (m); -         if(m==1|| m==2|| m==3) -cout<<"4"<<Endl; -         Else in{intK; -              for(i=m;; i++) to{k=sqrt (i); +                 if(K*K==I&AMP;&AMP;CMP (k)) Break; -             } the              for(j=m;; j--) *{k=sqrt (j); $                 if(K*K==J&AMP;&AMP;CMP (k)) Break;Panax Notoginseng             } -              the             if(I-M&LT;M-J) cout<<i<<Endl; +             Elsecout<<j<<Endl; A         } the     }  +     return 0; -}
View Code

HDU number of qualitative square

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.