NBUT 1224 Happiness Hotel 2010辽宁省赛

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

1
2
3

Sample Output

no solution
3
2

要求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             else
112                 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         else
118             printf("no solution\n");
119     }
120     return 0;
121 }
时间: 2025-01-05 19:48:51

NBUT 1224 Happiness Hotel 2010辽宁省赛的相关文章

[NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程

题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8871535 当d为完全平方数时无解 将√d表示成连分数的形式,例如: 当d不为完全平方数时,√d为无理数,那么√d总可以表示成: 记 当n为偶数时,x0=p,y0=q:当n为奇数时,x0=2p2+1,y0=2pq 求d在1000以内佩尔方程的最小正整数解的c++打表程序(正常跑比较慢,这个题需要离

2010辽宁省赛 NBUT 1222 English Game【字典树+DP】

[1222] English Game 时间限制: 1000 ms 内存限制: 131072 K 链接:Click Here! 问题描述 This English game is a simple English words connection game. The rules are as follows: there are N English words in a dictionary, and every word has its own weight v. There is a wei

2010辽宁省赛F(字典树,动态规划)

#include<bits/stdc++.h>using namespace std;int n,x;char s[10010];char a[31010];int val[100010];int ch[100010][30];int dp[100010];int main(){    while(~scanf("%d",&n))    {        scanf("%s",s+1);        int len=strlen(s+1);  

2010辽宁省赛E(Bellman_Ford最短路,状态压缩DP【三进制】)

#include<bits/stdc++.h>using namespace std;const int inf=0x3f3f3f3f;struct node{    int v,z,d,next;//存可以连接的点,用next存邻接表}a[10010];struct road{    int u,cnt,dis;//dis储存当前需要的钱数,即最短路算法里的权,u储存顶点,cnt储存组合数即状态压缩dp    road(int uu,int cntt,int diss)    {      

[ACM]辽宁省赛2010 (HZNU 1081-1089)

虽然退役了,但偶尔水几题醒醒脑还是不错的=_= 1085 Intermediary 暂时还没做 1081: Dinner 时间限制: 1 Sec  内存限制: 32 MB提交: 5  解决: 3[提交][状态][讨论版] [Edit] [TestData] 题目描述 Little A is one member of ACM team. He had just won the gold in World Final. To celebrate, he decided to invite all

2014辽宁省赛 Traveling

问题 K: Traveling 时间限制: 1 Sec  内存限制: 128 MB 提交: 13  解决: 4 [提交][状态][论坛] 题目描述 SH likes traveling around the world. When he arrives at a city, he will ask the staff about the number of cities that connected with this city directly. After traveling around 

辽宁省赛——杨鲁斯卡尔专场 -F

题意: 题意就是输入N以EOF结尾,形成1-N的数字序列,然后选取一个幸运数字,每隔幸运数字的长度就将数字从序列中删掉, 选取幸运数字的规则是最开始是2,之后删掉数字之后每次选取序列中除1和选过的幸运数字外最小的.3<=n<=10000) 样例输入20 30 样例输出6 8 提示 eg.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 For the first time, delete the last number in every tw

2010年辽宁省赛 NBUT 1218【DFS实现树的遍历与更新】

[1218] You are my brother 时间限制: 1000 ms 内存限制: 131072 K 链接:NBUT 1218 问题描述 Little A gets to know a new friend, Little B, recently. One day, they realize that they are family 500 years ago. Now, Little A wants to know whether Little B is his elder, youn

2014辽宁省赛 Repeat Number

问题 C: Repeat Number 时间限制: 1 Sec  内存限制: 128 MB 提交: 23  解决: 7 [cid=1073&pid=2&langmask=0">提交][状态][论坛] 题目描写叙述 Definition: a+b = c, if all the digits of c are same ( c is more than ten).then we call a and b are Repeat Number. My question is Ho