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 ...
随机推荐
- python删除所有自定义变量方法--转载
http://blog.sina.com.cn/s/blog_b2f983a50102yexs.html 当我们在pythonwin中创建多个变量后,通过dir()函数,可以看到所有已创建变量,这 ...
- 肿瘤基因组学数据库终结者:cBioPortal---转载
转载自:http://blog.sciencenet.cn/blog-1509670-1000479.html 随着芯片和高通量测序技术的广泛应用,在肿瘤研究领域积累了越来越多的基因组学数据,特别是像 ...
- Python day10 global关键字、函数递归、匿名函数、map函数的用法详解
1.global关键字 引用全局变量,在局部全局变量改变,也会改变,global相当于指针,将地址指向全局变量的name name='littlepage' def littepage(): glob ...
- Java 集合-Collection接口和迭代器的实现
2017-10-30 00:30:48 Collection接口 Collection 层次结构 中的根接口.Collection 表示一组对象,这些对象也称为 collection 的元素.一些 c ...
- scala 与 java 之间的关系
scala来源于java,但又高于java. scala的设计者Martin Odersky就是一个JAVA控,这位牛人设计了javac和编写了jdk中的通用代码.可以说java语言本身就是Marti ...
- Linux 设置程序开机自启动 (命令systemctl 和 chkconfig用法区别比较)
之前在Linux centos 7 上安装了apache 和mysql,当时并没有设置开机自动启动. 最近又重新练习网页,每次开机总是要手动启动httpd和mysqld,不方便,就想设置成开机自动启动 ...
- [.NET开发] C# 合并、拆分PDF文档
在整理文件时,将多个同类型文档合并是实现文档归类的有效方法,也便于文档管理或者文档传输.当然,也可以对一些比较大的文件进行拆分来获取自己想要的部分文档.可以任意地对文档进行合并.拆分无疑为我们了提供极 ...
- js-Client-side web APIs
APIs https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/ 简介: 应用程序接口(API) ...
- AND Graph CodeForces - 987F (状压)
链接 大意:给定$m$个数, 若$x\&y=0$, 则在$x$与$y$之间连一条无向边. 求无向图的连通块个数 暴力连边显然超时的, 可以通过辅助结点优化连边, 复杂度$O(n2^n)$ #i ...
- Java使用FFmpeg处理视频文件指南
Java使用FFmpeg处理视频文件指南 本文主要讲述如何使用Java + FFmpeg实现对视频文件的信息提取.码率压缩.分辨率转换等功能: 之前在网上浏览了一大圈Java使用FFmpeg处理音视频 ...