Love丶FFC's Blog

PAT乙级:1091 N-自守数

2020-04-23 22:44:05
阅读:1460   •   评论:13
标签:,

如果某个数 K 的平方乘以 N 以后,结果的末尾几位数等于 K,那么就称这个数为“N-自守数”。例如 3×92​2​​=25392,而 25392的末尾两位正好是 92,所以 92 是一个 3-自守数。

本题就请你编写程序判断一个给定的数字是否关于某个 N 是 N-自守数。

输入格式:

输入在第一行中给出正整数 M(≤20),随后一行给出 M 个待检测的、不超过 1000 的正整数。

输出格式:

对每个需要检测的数字,如果它是 N-自守数就在一行中输出最小的 N 和 NK​2​​ 的值,以一个空格隔开;否则输出 No。注意题目保证 N<10。

输入样例:

3
92 5 233

输出样例:

3 25392
1 25
No

编程语言:Python

解题思想:

1.穷举N的每种情况

2.利用字符串切片的操作判断是否为自守数

时间复杂度:O(N^2)

代码如下:

  1. NON = int(input())
  2.  
  3. Number = list(map(int, input().split())) # 将一行的输入转为列表
  4.  
  5. for i in range(NON): # 遍历该列表
  6. K = Number[i]
  7. Judge = False # 标记该数是否为自守数,默认为否
  8. for j in range(10): # 穷举N的每种情况
  9. N = j
  10. for k in range(len(str(K * K * N)), -1, -1): # 遍历字符串的长度,例如265962,顺序为6、5、4···
  11. if str(K) == str(K * K * N)[k:]: # 例如字符串为26532,[k:]的作用在于取字符串的后5-k位
  12. print(N, K * K * N)
  13. Judge = True
  14. break
  15. if Judge:
  16. break
  17. if not Judge:
  18. print("No")

评论板

共有 13 条评论

  1. cheap louis vuitton outlet

    I just wanted to thank you for the fast service. and even they look great. I received them a day earlier than expected. which include the I will definitely continue to buy from this site. blue jays I will recommend this site to my friends. Thanks!
    cheap louis vuitton outlet https://www.bestlouisvuittonoutlet.com/

  2. cheap jordans online

    I just wanted to thank you for the fast service. or even a they look great. I received them a day earlier than expected. the same as the I will definitely continue to buy from this site. blue jays I will recommend this site to my friends. Thanks!
    cheap jordans online https://www.realjordansretro.com/

  3. jordans for cheap

    I just wanted to thank you for the fast service. potentially they look great. I received them a day earlier than expected. which includes the I will definitely continue to buy from this site. in any event I will recommend this site to my friends. Thanks!
    jordans for cheap https://www.realcheapretrojordanshoes.com/

  4. cheap louis vuitton outlet

    I just wanted to thank you for the fast service. as they look great. I received them a day earlier than expected. similar to the reduction I will definitely continue to buy from this site. manner in which I will recommend this site to my friends. Thanks!
    cheap louis vuitton outlet https://www.cheapreallouisvuitton.com/

  5. cheap louis vuitton online

    I just wanted to thank you for the fast service. perhaps they look great. I received them a day earlier than expected. since the I will definitely continue to buy from this site. either way I will recommend this site to my friends. Thanks!
    cheap louis vuitton online https://www.louisvuittonsoutletstore.com/

  6. FoorryNox

    7 minutes, standard deviation SD 31 cheap propecia 10mg Fausto, USA 2022 06 19 10 03 30

  7. cheap real jordans

    Read reviews and was a little hesitant since I had already inputted my order. or perhaps a but thank god, I had no issues. themselves received item in a timely matter, they are in new condition. in any event so happy I made the purchase. Will be definitely be purchasing again.
    cheap real jordans https://www.cheapsneakeronline.com/

  8. original louis vuittons outlet

    Read reviews and was a little hesitant since I had already inputted my order. or it may be but thank god, I had no issues. for instance received item in a timely matter, they are in new condition. an invaluable so happy I made the purchase. Will be definitely be purchasing again.
    original louis vuittons outlet https://www.louisvuittonsoutletonline.com/

  9. Preliaf

    As such, this matter is ripe for adjudication canadian levitra Follow up ranged from 8 25 yr

  10. Vqeove

    purchase fenofibrate online cheap purchase fenofibrate sale buy tricor 200mg without prescription

  11. Absbhe

    order tadalafil sale sildenafil 100mg generic female viagra pill

  12. Cbbrih

    how to buy ketotifen buy sinequan without prescription purchase imipramine sale

  13. Pyhvgf

    order acarbose 25mg generic micronase canada buy fulvicin 250mg for sale

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名:http://www.loveffc:8080,点击跳转,完全移植后将去除端口号。

Copyright © 2018 - 2021 FFC的小站 - 滇 ICP 备 18010780 号 - 1

- Powered by WordPress & AliYun · Theme by FFC -

- Environment by Windows & XAMPP · Designed by WebStorm & VSCode -

已运行:

访问量:507489