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
 #include <iostream>
#include <cmath>
using namespace std; int can[];
int a[][];
int x[],y[],t[];
int h1,h2;
int bb,ee,xx,yx,c,n; void gui(int ji,int many,int ma,int kk)
{
if (ji<kk)
gui(ji+,a[ma][(ji-)%a[ma][]+],ma,kk);
else
{
h1=;
h2=;
x[]=many;
y[]=;
return;
}
for (int i=;i<=h1;i++)
t[i]=x[i];
for (int i=;i<=h2;i++)
x[i]=y[i];
for (int i=;i<=h1;i++)
y[i]=t[i];
c=h1;
h1=h2;
h2=c;
for (int i=;i<=h2;i++)
{
if (i<=h1)
x[i]+=many*y[i];
else
x[i]=many*y[i];
}
if (h2>h1)
h1=h2;
for (int i=;i<h1;i++)
{
if (x[i]>=)
{
x[i+]+=x[i]/;
x[i]%=;
}
}
while (x[h1]>=)
{
x[h1+]=x[h1]/;
x[h1]%=;
h1++;
}
x[]=h1;
} int main()
{ for (int i=;i<=;i++)
can[i*i]=true;
for (int i=;i<=;i++)
if (!can[i])
{
a[i][]=;
bb=;
ee=(int)sqrt((double)i);
a[i][]=ee;
ee=-ee;
xx=bb;
yx=ee;
xx=-yx;
yx=i-yx*yx;
n=;
while ((xx-yx)*(xx-yx)<i||xx>=)
{
xx-=yx;
n++;
}
a[i][]=n;
c=xx;
xx=yx;
yx=c;
while (xx!=bb||yx!=ee)
{
a[i][]++;
c=xx;
xx=-yx;
yx=i-yx*yx;
yx=yx/c;
n=;
while ((xx-yx)*(xx-yx)<i||xx>=)
{
xx-=yx;
n++;
}
a[i][a[i][]]=n;
c=xx;
xx=yx;
yx=c;
}
}
int i;
while (scanf("%d",&i)!=EOF)
{
if (!can[i])
{
if (a[i][]%)
gui(,a[i][],i,a[i][]*);
else
gui(,a[i][],i,a[i][]);
for (int j=x[];j>=;j--)
printf("%d",x[j]);
printf("\n");
}
else
printf("no solution\n");
}
return ;
}

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

  1. NBUT 1222 English Game 2010辽宁省赛

    Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...

  2. NBUT 1223 Friends number 2010辽宁省赛

    Time limit  1000 ms Memory limit   131072 kB Paula and Tai are couple. There are many stories betwee ...

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

    题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ...

  4. NBUT 1221 Intermediary 2010辽宁省赛

    Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...

  5. NBUT 1225 NEW RDSP MODE I 2010辽宁省赛

    Time limit  1000 ms Memory limit  131072 kB Little A has became fascinated with the game Dota recent ...

  6. NBUT 1218 You are my brother 2010辽宁省赛

    Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...

  7. NBUT 1220 SPY 2010辽宁省赛

    Time limit  1000 ms Memory limit  131072 kB The National Intelligence Council of X Nation receives a ...

  8. NBUT 1219 Time 2010辽宁省赛

    Time limit   1000 ms Memory limit   131072 kB Digital clock use 4 digits to express time, each digit ...

  9. NBUT 1217 Dinner 2010辽宁省赛

    Time limit  1000 ms Memory limit  32768 kB Little A is one member of ACM team. He had just won the g ...

随机推荐

  1. UVa 1152 和为0的4个值(二分查找)

    https://vjudge.net/problem/UVA-1152 题意:给定4个n元素集合A,B,C,D,要求分别从中选取一个元素a,b,c,d,使得a+b+c+d=0.问有多少种取法. 思路: ...

  2. Linux——进程管理简单学习笔记(二)

    计划任务: 为什么要设置计划任务 : 实现数据库备份,发送系统通知神马的..... 计划任务的命令: 一: at :  安排作业在某一时刻执行一次 nbatch    安排作业在系统负载不重时执 行一 ...

  3. 转载:oracle 11g ADG实施手册(亲测,已成功部署多次)

    https://www.cnblogs.com/yhfssp/p/7815078.html 一:实验环境介绍 虚拟机系统: RHEL Linux 6.4(64位) 数据库版本: Oracle 11gR ...

  4. .NET身份证验证

    身份证号码编码规则及校验位校验算法 算法地址:http://jingyan.baidu.com/article/7f41ececff944a593d095c8c.html 简单验证长度 /// < ...

  5. ADO.NET 批量插入

    在.Net1.1中无论是对于批量插入整个DataTable中的所有数据到数据库中,还是进行不同数据源之间的迁移,都不是很方便.而 在.Net2.0中,SQLClient命名空间下增加了几个新类帮助我们 ...

  6. Flutter实战:手把手教你写Flutter Plugin

    前言 如果你对移动端有所关注,那么你一定会听说过Flutter.得益于Google,Flutter一经推出便得受到了广泛关注.很多开发者跃跃欲试,国内部分大厂,诸如美团.闲鱼等团队已经开始了Flutt ...

  7. Java JDK5新特性-增强for

    2017-10-31 00:02:16 格式: for(元素数据类型 变量:数组或者Collection集合) { 使用变量即可,该变量即是元素 } int arr[] = {1,2,3,4,5}; ...

  8. Android scrollview和GridView混合使用

    在开发中用到了需要ScrollView嵌套GridView的情况,由于这两款控件都自带滚动条,当他们碰到一起的时候便会出问题,即GridView会显示不全.解决办法,自定义一个GridView控件 p ...

  9. [转]TOMCAT启动提示NB: JAVA_HOME should point to a JDK not a JRE解决

    来源:http://blog.csdn.net/caozhongyan/article/details/6602759 本人使用的Tomcat版本为apache-tomcat-6.0.18(用的是解压 ...

  10. SQL 函数 DateDiff()

    DateDiff(interval, date1, date2 [,firstdayofweek[, firstweekofyear]]) 描述 返回两个日期之间的时间间隔. 语法 DateDiff( ...