我来我网
https://5come5.cn
 
您尚未 登录  注册 | 菠菜 | 软件站 | 音乐站 | 邮箱1 | 邮箱2 | 风格选择 | 更多 » 
 

本页主题: 昨天acm热身赛的a题 显示签名 | 打印 | 加为IE收藏 | 收藏主题 | 上一主题 | 下一主题

星坟



性别: 帅哥 状态: 该用户目前不在线
等级: 希望之光
家族: 格格乐心
发贴: 1558
威望: 0
浮云: 310
在线等级:
注册时间: 2006-09-10
最后登陆: 2013-02-21

5come5帮你背单词 [ sixteen /'siks'ti:n/ num. 十六 ]


昨天acm热身赛的a题

A.  A Simple Game

--------------------------------------------------------------------------------

Time Limit: 1.0 Seconds  Memory Limit: 65536K
Total Runs: 0  Accepted Runs: 0

--------------------------------------------------------------------------------


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.

Output
Output consists of T lines. Each line contains an integer, the minimum number of presses for the corresponding test case.
Constraints
1 ≤ T ≤ 100, 1 ≤ N ≤ 10000
Sample Input
2
2
3

Sample Output
3
7

Sample Input/Output Clarification
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).







怎么实现内存啊  不能用10000维的数组啊!!!
顶端 Posted: 2008-05-02 09:46 | [楼 主]
magian



性别: 帅哥 状态: 该用户目前不在线
等级: 栋梁之材
发贴: 958
威望: 0
浮云: 1947
在线等级:
注册时间: 2006-11-05
最后登陆: 2008-06-29

5come5帮你背单词 [ nineteen /'nain'ti:n/ num. 十九 ]


你定义2维数组是不行的,我也试过了,定义10000,元素就有100000000个,大小已经超过默认栈的大小了,如果想用,就把数组定义成全局,可以运行,但是内存使用和运行时间都超标

我觉得这个题目有递推关系
顶端 Posted: 2008-05-02 12:01 | [1 楼]
我来我网·5come5 Forum » 程序员之家

Total 0.010961(s) query 6, Time now is:11-22 00:27, Gzip enabled
Powered by PHPWind v5.3, Localized by 5come5 Tech Team, 黔ICP备16009856号