求任意整数的200次平方的末两位

一道中学生的题目困扰了我好久啊,从吃晚饭时间到现在...

求x的n次方的末两位数。令y=x**n,则y的末两位数与x的末两位数有关。

规律就是从2开始,每20个数是一个循环

View Code
for x in range(2, 100):          #x为底数
y=x%100      #y为幂的最后两位
s=""
for n in range(2,201):    #n为指数
init=y        #init保留上一次y的值
y=y*x        #每次乘以一个x
y = y % 100       #对y用100取模,值为最后两位数
if y==init:          # 如果本次算值与上次计算值相同,则不需继续计算
break
if y==x:
s
=r"Special Number"
print( "%-2d"%x, "%.2d" %y, s)

('2 ', '76', '')
('3 ', '01', '')
('4 ', '76', '')
('5 ', '25', '')
('6 ', '76', '')
('7 ', '01', '')
('8 ', '76', '')
('9 ', '01', '')
('10', '00', '')
('11', '01', '')
('12', '76', '')
('13', '01', '')
('14', '76', '')
('15', '25', '')
('16', '76', '')
('17', '01', '')
('18', '76', '')
('19', '01', '')
('20', '00', '')
('21', '01', '')


('22', '76', '')
('23', '01', '')
('24', '76', '')
('25', '25', 'Special Number')
('26', '76', '')
('27', '01', '')
('28', '76', '')
('29', '01', '')
('30', '00', '')
('31', '01', '')
('32', '76', '')
('33', '01', '')
('34', '76', '')
('35', '25', '')
('36', '76', '')
('37', '01', '')
('38', '76', '')
('39', '01', '')
('40', '00', '')
('41', '01', '')


('42', '76', '')
('43', '01', '')
('44', '76', '')
('45', '25', '')
('46', '76', '')
('47', '01', '')
('48', '76', '')
('49', '01', '')
('50', '00', '')
('51', '01', '')
('52', '76', '')
('53', '01', '')
('54', '76', '')
('55', '25', '')
('56', '76', '')
('57', '01', '')
('58', '76', '')
('59', '01', '')
('60', '00', '')
('61', '01', '')
('62', '76', '')
('63', '01', '')
('64', '76', '')
('65', '25', '')
('66', '76', '')
('67', '01', '')
('68', '76', '')
('69', '01', '')
('70', '00', '')
('71', '01', '')
('72', '76', '')
('73', '01', '')
('74', '76', '')
('75', '25', '')
('76', '76', 'Special Number')
('77', '01', '')
('78', '76', '')
('79', '01', '')
('80', '00', '')
('81', '01', '')
('82', '76', '')
('83', '01', '')
('84', '76', '')
('85', '25', '')
('86', '76', '')
('87', '01', '')
('88', '76', '')
('89', '01', '')
('90', '00', '')
('91', '01', '')
('92', '76', '')
('93', '01', '')
('94', '76', '')
('95', '25', '')
('96', '76', '')
('97', '01', '')
('98', '76', '')
('99', '01', '')

 

posted @ 2011-08-01 19:20  牛皮糖NewPtone  阅读(753)  评论(0编辑  收藏  举报