Love丶FFC's Blog

PAT乙级:1087 有多少不同的值

2020-04-19 21:05:43
阅读:696   •   评论:7
标签:,

当自然数 n 依次取 1、2、3、……、N 时,算式 ⌊n/2⌋+⌊n/3⌋+⌊n/5⌋ 有多少个不同的值?(注:⌊x⌋ 为取整函数,表示不超过 x的最大自然数,即 x 的整数部分。)

输入格式:

输入给出一个正整数 N(2≤N≤10​4​​)。

输出格式:

在一行中输出题面中算式取到的不同值的个数。

输入样例:

2017

输出样例:

1480

编程语言:Python

解题思想:

1.利用int进行取整

2.利用Python中set的性质进行去重

时间复杂度:O(N)

代码如下:

  1. N = int(input())
  2. Value = list() # 存放每个算式的值
  3. for i in range(1, N + 1):
  4. Value.append(int(i / 2) + int(i / 3) + int(i / 5)) # 将算式的值添加到列表中
  5.  
  6. Value = set(Value) # 将列表转为集合,这样可以去除重复的值
  7. print(len(Value)) # 集合的长度就是算式取到的不同值的个数

评论板

共有 7 条评论

  1. authentic cheap jordans

    I just wanted to thank you for the fast service. and they look great. I received them a day earlier than expected. simillar to the I will definitely continue to buy from this site. regardless I will recommend this site to my friends. Thanks!
    authentic cheap jordans https://www.realjordansretro.com/

  2. cheap louis vuitton handbags

    I just wanted to thank you for the fast service. or perhaps they look great. I received them a day earlier than expected. which include the I will definitely continue to buy from this site. in any event I will recommend this site to my friends. Thanks!
    cheap louis vuitton handbags https://www.louisvuittonsoutletstore.com/

  3. authentic louis vuitton outlet

    I just wanted to thank you for the fast service. also known as they look great. I received them a day earlier than expected. choose the I will definitely continue to buy from this site. you ultimately choose I will recommend this site to my friends. Thanks!
    authentic louis vuitton outlet https://www.cheapreallouisvuitton.com/

  4. jordans for cheap

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

  5. FoorryNox

    Description Preliminary data from our lab and others demonstrates that CD53 expression is induced during early B cell development, and may play a role in protecting both normal and malignant B cells from apoptosis best price cialis

  6. louis vuittons outlet

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

  7. Preliaf

    Among the 225 total patients enrolled in APOLLO, 126 56 fulfilled criteria to be included in the prespecified cardiac subpopulation cheap cialis from india

--------查看该分类下最新文章--------
^
新版博客正在完善中!域名: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 -

已运行:

访问量:503915