NBUT 1224 Happiness Hotel 2010遼寧省賽

來源:互聯網
上載者:User

標籤:nbsp   sid   lease   little   get   bsp   most   and   center   

Time limit 1000 ms

Memory limit 131072 kB

The life of Little A is good, and, he managed to get enough money to run a hotel. The best for him is that 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 has a wonderful plan that he will keep one most beautiful reception whose size is 1()(which means the reception is 1 square meter). There are other k rooms that have the same area, and the area is x^2(), x is an integer; Little A wants his hotel to be a square. Little A is a good thinker, but not a good maker. As his poor performance on math, he cannot calculate the least area needed to build such a hotel of his will. Now, this task belongs to you, 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 not be any vacant place.

 

Input

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

Output

Output one integer d, means the hotel’s area is 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


要求n*a*a+1=b*b,a,b都是整數,n<=1000,看有沒有這樣的a,b

網上copy的代碼。。還沒理解還沒自己寫。。先記著
來自http://blog.sina.com.cn/s/blog_7e9a88f70100sot1.html
  1 #include <iostream>  2 #include <cmath>  3 using namespace std;  4   5 int can[1005];  6 int a[10005][605];  7 int x[6005],y[6005],t[6005];  8 int h1,h2;  9 int bb,ee,xx,yx,c,n; 10  11 void gui(int ji,int many,int ma,int kk) 12 { 13     if (ji<kk) 14         gui(ji+1,a[ma][(ji-1)%a[ma][600]+1],ma,kk); 15     else 16     { 17         h1=1; 18         h2=1; 19         x[1]=many; 20         y[1]=1; 21         return; 22     } 23     for (int i=1;i<=h1;i++) 24         t[i]=x[i]; 25     for (int i=1;i<=h2;i++) 26         x[i]=y[i]; 27     for (int i=1;i<=h1;i++) 28         y[i]=t[i]; 29     c=h1; 30     h1=h2; 31     h2=c; 32     for (int i=1;i<=h2;i++) 33     { 34         if (i<=h1) 35             x[i]+=many*y[i]; 36         else 37             x[i]=many*y[i]; 38     } 39     if (h2>h1) 40         h1=h2; 41     for (int i=1;i<h1;i++) 42     { 43         if (x[i]>=10) 44         { 45             x[i+1]+=x[i]/10; 46             x[i]%=10; 47         } 48     } 49     while (x[h1]>=10) 50     { 51         x[h1+1]=x[h1]/10; 52         x[h1]%=10; 53         h1++; 54     } 55     x[0]=h1; 56 } 57  58 int main() 59 { 60  61     for (int i=1;i<=31;i++) 62         can[i*i]=true; 63     for (int i=1;i<=1000;i++) 64     if (!can[i]) 65     { 66         a[i][600]=1; 67         bb=1; 68         ee=(int)sqrt((double)i); 69         a[i][0]=ee; 70         ee=-ee; 71         xx=bb; 72         yx=ee; 73         xx=-yx; 74         yx=i-yx*yx; 75         n=0; 76         while ((xx-yx)*(xx-yx)<i||xx>=0) 77         { 78             xx-=yx; 79             n++; 80         } 81         a[i][1]=n; 82         c=xx; 83         xx=yx; 84         yx=c; 85         while (xx!=bb||yx!=ee) 86         { 87             a[i][600]++; 88             c=xx; 89             xx=-yx; 90             yx=i-yx*yx; 91             yx=yx/c; 92             n=0; 93             while ((xx-yx)*(xx-yx)<i||xx>=0) 94             { 95                 xx-=yx; 96                 n++; 97             } 98             a[i][a[i][600]]=n; 99             c=xx;100             xx=yx;101             yx=c;102         }103     }104     int i;105     while (scanf("%d",&i)!=EOF)106     {107         if (!can[i])108         {109             if (a[i][600]%2)110                 gui(1,a[i][0],i,a[i][600]*2);111             else112                 gui(1,a[i][0],i,a[i][600]);113             for (int j=x[0];j>=1;j--)114                 printf("%d",x[j]);115             printf("\n");116         }117         else118             printf("no solution\n");119     }120     return 0;121 }

 

NBUT 1224 Happiness Hotel 2010遼寧省賽

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.