Nbut 1224 Happiness Hotel 2010 Liaoning Provincial Race

Source: Internet
Author: User

Time limit MS

Memory Limit 131072 KB

The life of Little A are good, and, he managed to get enough money to run A hotel. The best for him is so he need not go to work outside, just wait for the money to go into his pocket. Little A wants everything to be perfect, he had A wonderful plan that he would keep one most beautiful reception whose size is 1 () (which means, the reception is 1 square meter). There is other K rooms that has the same area, and the area is a x^2 (), x is an integer; Little A wants he hotel to be a square. Little A is a good thinker and not a good maker. As his poor performance in math, he cannot calculate the least area needed to build such a hotel's his'll. Now, the this task belongs to you, the solve this problem to make Little A ' s dream of Happy Hotel come true. Please be careful, the whole area should only contain k rooms, and the reception, there should is no vacant place.

Input

There is several test cases.
Each case is contains only one integer k (1<=k<=1000), the number of rooms the hotel should has in one line.
Proceed to the end of file.

Output

Output one integer d, means the hotel's area was d^2 (If there is no answer, output "no solution"). The output of one test case occupied exactly one line.

Sample Input

123

Sample Output

No Solution32


Requirements n*a*a+1=b*b,a,b are integers, n<=1000, see there is no such a, b

Online copy of the code: I haven't yet understood how to write it myself. Just remember.
From http://blog.sina.com.cn/s/blog_7e9a88f70100sot1.html
1#include <iostream>2#include <cmath>3 using namespacestd;4 5 intcan[1005];6 inta[10005][605];7 intx[6005],y[6005],t[6005];8 inth1,h2;9 intBb,ee,xx,yx,c,n;Ten  One voidGuiintJiintMany,intMaintKK) A { -     if(ji<KK) -GUI (ji+1, a[ma][(ji-1)%a[ma][ -]+1],ma,kk); the     Else -     { -h1=1; -H2=1; +x[1]=many; -y[1]=1; +         return; A     } at      for(intI=1; i<=h1;i++) -t[i]=X[i]; -      for(intI=1; i<=h2;i++) -x[i]=Y[i]; -      for(intI=1; i<=h1;i++) -y[i]=T[i]; inC=H1; -h1=H2; toH2=C; +      for(intI=1; i<=h2;i++) -     { the         if(i<=H1) *x[i]+=many*Y[i]; $         ElsePanax Notoginsengx[i]=many*Y[i]; -     } the     if(h2>H1) +h1=H2; A      for(intI=1; i) the     { +         if(x[i]>=Ten) -         { $x[i+1]+=x[i]/Ten; $x[i]%=Ten; -         } -     } the      while(x[h1]>=Ten) -     {Wuyix[h1+1]=x[h1]/Ten; thex[h1]%=Ten; -h1++; Wu     } -x[0]=H1; About } $  - intMain () - { -  A      for(intI=1; i<= to; i++) +can[i*i]=true; the      for(intI=1; i<= +; i++) -     if(!Can[i]) $     { thea[i][ -]=1; thebb=1; theEe= (int) sqrt (Double) (i); thea[i][0]=ee; -ee=-ee; inxx=BB; theyx=ee; thexx=-Yx; Aboutyx=i-yx*Yx; then=0; the          while((Xx-yx) * (Xx-yx) <i| | xx>=0) the         { +xx-=Yx; -n++; the         }Bayia[i][1]=N; theC=xx; thexx=Yx; -yx=C; -          while(xx!=bb| | yx!=ee) the         { thea[i][ -]++; theC=xx; thexx=-Yx; -yx=i-yx*Yx; theyx=yx/C; then=0; the              while((Xx-yx) * (Xx-yx) <i| | xx>=0)94             { thexx-=Yx; then++; the             }98a[i][a[i][ -]]=N; AboutC=xx; -xx=Yx;101yx=C;102         }103     }104     inti; the      while(SCANF ("%d", &i)! =EOF)106     {107         if(!Can[i])108         {109             if(a[i][ -]%2) theGui1, a[i][0],i,a[i][ -]*2);111             Else theGui1, a[i][0],i,a[i][ -]);113              for(intj=x[0];j>=1; j--) theprintf"%d", X[j]); theprintf"\ n"); the         }117         Else118printf"No solution\n");119     } -     return 0;121}

Nbut 1224 Happiness Hotel 2010 Liaoning Provincial Race

Related Article

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.