UESTC1141 A Simple Game

游戏策略:简易游戏最少操作
探讨了一款基于N*N矩阵的游戏策略问题,目标是最少次数地触发开关以点亮所有灯泡。文章提供了完整的算法思路及C++实现代码。

http://acm.uestc.edu.cn/ShowProblem.aspx?ProblemID=1141&ContestID=24

 A Simple Game  
Time Limit:1000ms  Memory Limit: 65535K
Submited:478  Accepted:50
Cached at 2010/3/29 22:49:14
Description
Alice likes to play games. One day she meets such a game. There are N * N switches arranged in an N * N array. Pressing a switch would change its state, from 'off' to 'on' or from 'on' to 'off'. In addition, if a switch at row r and column c is pressed, then all switches with coordinate (k * r, k * c) will change state, with integer k > 1. Initially all switches are 'off'.

For example, in the picture above, white buttons represent switches turned 'off' and colored ones represent switches turned 'on'. Initially all buttons are white. If the button at (2,2) is pressed, then buttons at (2,2), (4,4) will change state(represented with orange color). And if one presses the button (2,1), buttons at (2,1) and (4,2) will change from 'off' to 'on'(represented with gray color).
The goal of the game is to turn 'on' all the switches (i.e. when you finish the game, all the switches must be at the state of 'on') and the player must do that with as few presses as possible. Now Alice would like your help.

 


Input
The first line of input file is an integer T, the number of test cases. T lines follow, each contain an integer N, the dimension of the array in one game.
1 ≤ T ≤ 100, 1 ≤ N ≤ 10000

 


Output
Output consists of T lines. Each line contains an integer, the minimum number of presses for the corresponding test case.

 


Sample Input
2
2
3

Sample Output
3
7

Hint
For test case 1, press (1,1) (1,2) (2,1).
For test case 2, press (1,1) (1,2) (1,3) (2,1) (2,3) (3,1) (3,2).

Source
The 5th UESTC Programming Contest Preliminary
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值