链接:ZOJ1239

Hanoi Tower Troubles Again!

Description

People stopped moving discs from peg to peg after they know the number of steps needed to complete the entire task. But on the other hand, they didn't not stopped thinking about similar puzzles with the Hanoi Tower. Mr.S invented a little game on it. The game consists of N pegs and a LOT of balls. The balls are numbered 1,2,3... The balls look ordinary, but they are actually magic. If the sum of the numbers on two balls is NOT a square number, they will push each other with a great force when they're too closed, so they can NEVER be put together touching each other.

The player should place one ball on the top of a peg at a time. He should first try ball 1, then ball 2, then ball 3... If he fails to do so, the game ends. Help the player to place as many balls as possible. You may take a look at the picture above, since it shows us a best result for 4 pegs.

Input

The first line of the input contains a single integer T, indicating the number of test cases. (1<=T<=50) Each test case contains a single integer N(1<=N<=50), indicating the number of pegs available.

Output

For each test case in the input print a line containing an integer indicating the maximal number of balls that can be placed. Print -1 if an infinite number of balls can be placed.

Sample Input

2
4
25

Sample Output

11
337

HINT

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std; ll sum = ;
ll n;
int flag = ; int haha[] = {};
ll work(ll x, int i)
{ if( flag == n)
return ; ll t = x + haha[i]; double tt = pow(double(t),1.0 / );
if(fabs(tt - (ll)(tt)) < 0.000001)
{
flag = ;
haha[i] = x;
return + work(x+,);
}
else
{
if(haha[ ( i + ) % n ] == )
{
haha[i+] = x;
flag = ;
return +work(x + , );
}
else
{
flag++;
return work(x, (i+)%n);
}
}
}
int main()
{
//freopen("made.txt","w",stdout);
int T;
cin>>T;
while(T--)
{
cin>>n;
haha[] = ;
sum = work(, );
cout<<sum<<endl;
memset(haha,,sizeof(haha));
flag = ;
}
return ;
}

ZOJ-1239 Hanoi Tower Troubles Again!的更多相关文章

  1. HDU1329 Hanoi Tower Troubles Again!——S.B.S.

    Hanoi Tower Troubles Again! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  2. HDU 1329 Hanoi Tower Troubles Again!(乱搞)

    Hanoi Tower Troubles Again! Problem Description People stopped moving discs from peg to peg after th ...

  3. zoj 2954 Hanoi Tower

    Hanoi Tower Time Limit: 2 Seconds Memory Limit: 65536 KB You all must know the puzzle named "Th ...

  4. 10276 - Hanoi Tower Troubles Again!(思维,模拟)

    People stopped moving discs from peg to peg after they know the number of steps needed to complete t ...

  5. 【HDOJ】1329 Hanoi Tower Troubles Again!

    水题,搞清楚hanoi的定义就好做了. /* 1329 */ #include <cstdio> #include <cstring> #include <cstdlib ...

  6. hdu 1329 Hanoi Tower Troubles Again!

    找规律的题目an=an-1+(i+i%2)/2*2; ;}

  7. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  8. 汉诺塔 Hanoi Tower

    电影<猩球崛起>刚开始的时候,年轻的Caesar在玩一种很有意思的游戏,就是汉诺塔...... 汉诺塔源自一个古老的印度传说:在世界的中心贝拿勒斯的圣庙里,一块黄铜板上插着三支宝石针.印度 ...

  9. 3-6-汉诺塔(Hanoi Tower)问题-栈和队列-第3章-《数据结构》课本源码-严蔚敏吴伟民版

    课本源码部分 第3章  栈和队列 - 汉诺塔(Hanoi Tower)问题 ——<数据结构>-严蔚敏.吴伟民版        源码使用说明  链接☛☛☛ <数据结构-C语言版> ...

随机推荐

  1. Winform TextBox中只能输入数字的几种常用方法(C#)

    方法一: private void tBox_KeyPress(object sender, KeyPressEventArgs e) { ; //禁止空格键 )) return; //处理负数 if ...

  2. mysql event_scheduler运行一段时间后 自动关闭

    应该是你重启过电脑或重启过服务了.  SELECT * FROM mysql.event;SET GLOBAL event_scheduler = 1; -- 开启定时器 0:off 1:on SHO ...

  3. 基于jquery上的轻量级《数据模板解析》插件

    1.先上一个栗子. <!doctype html> <html lang="en"> <head> <meta charset=" ...

  4. 使用ZIM桌面维基做笔记

    最近尝试了使用ZIM做笔记,感觉还不错 ubuntu下直接到软件中心即可安装,或者 sudo apt-get install zim windows下的到此下载http://www.glump.net ...

  5. 将List下载到本地保存为Excel

    直接附上代码 /// <summary> /// 将List保存为Excel /// </summary> /// <typeparam name="T&quo ...

  6. 20145205 《Java程序设计》实验报告五:Java网络编程及安全

    20145205 <Java程序设计>实验报告五:Java网络编程及安全 实验要求 1.掌握Socket程序的编写: 2.掌握密码技术的使用: 3.客户端中输入明文,利用DES算法加密,D ...

  7. css解决div的各种浏览器兼容性问题

    方法一: min-height:500px;/*解决ie8.9.ff.chromet*/ height:100%;/*解决ie6.7*/ _height:500px;/*解决ie6超出自动溢出*/ 方 ...

  8. JAVA入门

    编译型语言:高级语言代码经过编译器,一次性翻译为特定系统可以硬件执行的机器码,并包装成该平台所识别的可执行程序. 但是不同平台(系统)的机器码不同,所以编译后的可执行程序无法移植到其他平台.但是因为是 ...

  9. 轻量级队列beanstalkd

    一.基本Beanstalkd,一个高性能.轻量级的分布式内存队列系统,最初设计的目的是想通过后台异步执行耗时的任务来降低高容量Web应用系统的页面访问延迟,支持过有9.5 million用户的Face ...

  10. MySQL运行状态show status详解

    状态名 作用域 详细解释 Aborted_clients Global 由于客户端没有正确关闭连接导致客户端终止而中断的连接数 Aborted_connects Global 试图连接到MySQL服务 ...