Python语言初学(为机器学习做准备) Avaricious Maryanna

来源:互联网 发布:k歌软件哪个好 编辑:程序博客网 时间:2024/06/06 03:56

Avaricious Maryanna Avaricious Maryanna

很巧的情况下学了python,今天上午刚看了两个小时python3,然后下午打比赛就用到了。因为py有个特点,整数可以无限大,不会出现相乘溢出的情况。

昨天去图书馆,结果工程书库没开门,在三楼南书库转了转,里面有很多外文书籍,很惊喜地发现了我想要的python学习书。而且是最新版的新书,全英的,wow。看了不到两章就在程序设计比赛中用到了。

python是动态语言,属于解释型的纯OO Language。

上面是两个链接,同一道题。题目来源 Google Cup.

下面py代码 及 题面。(代码中可能有些搞笑的写法,刚学。。。)

在终端中打表语句

for j in range(501):    st = int(10 ** (j - 1))    ed = int(10 ** j)      for i in range(st, ed):           if i * i % ed == i: print(i)

解题代码

start = ([-1])start.append([-1, 0, 1, 5, 6])start.append([-1, 25, 76])start.append([-1, 376, 625])start.append([-1, 9376])start.append([-1, 90625])start.append([-1, 109376, 890625])for bit in range(7, 503):start.append([-1])ed = int(10 ** (bit - 1))mod = ed * 10for i in range(4, 0, -1):for st in start[bit - i]:if st == -1: continuefor it in range(0, 10):var = it * ed + stif var <= ed or var > mod: continueif var * var % mod == var :start[bit].append(var)start[bit].sort()T = int(input())kase = 0while T > 0:T -= 1n = int(input())kase += 1print("Case #%d: " % (kase), end = '')if len(start[n]) == 1:print("Impossible")else:for i in range(1, len(start[n]) - 1):print(start[n][i], end = ' ')print(start[n][-1])

AVARY - Avaricious Maryanna

no tags 

After Maryanna found the treasure buried by 27 pilots in a secret cave, she wanted to leave there immediately. Unfortunately, finding the door closed because of the overweight treasure she carried, she had to find out the password of the lock. She remembered someone had told her the password is an N-digit natural decimal integer (without extra leading zeroes), and the N least significant digits of any positive integral power of that integer is same as itself. She, being a smart girl, came up with all the possible answers within 1 minute. After a few times of tries, she escaped from that cave successfully. To show your intelligence you may solve the same task with your computer within only 10 seconds!

Input

The first line contains T (T <= 1000), the number of test cases. T lines follow, each contains a single positive integer N(N<= 500).

Output

For each test case, output a single line, which should begin with the case number counting from 1, followed by all the possible passwords sorted in increasing order. If no such passwords exist, output Impossible instead. See the sample for more format details.

Example

Input:221Output:Case #1: 25 76Case #2: 0 1 5 6
 Submit solution!



原创粉丝点击