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
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
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辽宁省赛的更多相关文章
- NBUT 1222 English Game 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...
- NBUT 1223 Friends number 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
- [NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程
题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ...
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- 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 ...
- 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 ...
- NBUT 1220 SPY 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- 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 ...
随机推荐
- django 数据库同步
python manage.py makemigrations python manage.py migrate
- STL__网上资料
1. http://bbs.csdn.net/topics/370029802 #include <iostream> #include <limits> #include & ...
- 【Python】给图片添加水印的Python及Golang实现
前言 不知道大家有没有这样的习惯,一篇比较得意的博客在发表一段时间之后会特别关注,前段时间一篇写到凌晨的博客被 码迷 这个网关爬取之后发表了,因为搜索引擎先爬取码迷的,所以我的博客无法被搜索到,即使直 ...
- hdu 5724-Chess(状态压缩+sg函数)
hdu 5724-Chess 代码: #include<bits/stdc++.h> using namespace std; ; <<N]; bool S[N]; void ...
- 3.4 复杂的x86指令举例
计算机组成 3 指令系统体系结构 3.4 复杂的x86指令举例 x86作为复杂指令系统的代表,自然会有不少相当复杂的指令.在这一节我们将会看到其中有代表性的一些例子. 关于复杂的x86指令,我们这里举 ...
- Java 本地环境设置
如果你希望在你的本地环境中设置 Java 程序环境,下面的这部分将会指导你在你的本地计算机上下载和设置 Java 环境.你可以按照下面的步骤进行. Java SE 目前是免费下载的,你可以通过单击下面 ...
- MySql 定时完成备份
<?php /*定时备份数据库文件*/ //设置时区 date_default_timezone_set('PRC'); //创建目录 $dirname = 'e:/mysql_dump/'.d ...
- HDU-5001 Walk (概率DP)
Problem Description I used to think I could be anything, but now I know that I couldn't do anything. ...
- n阶汉诺塔 记住吧。。
#include "bits/stdc++.h" using namespace std; int c; void move(char a,int n,char b) { prin ...
- 使用POI导入EXCEL报java.lang.IncompatibleClassChangeError
使用POI导入xls格式的excel报java.lang.IncompatibleClassChangeError异常,而导入xlsx正常. oracle.apps.fnd.framework.OAE ...