VK Cup 2018 - Wild-card Round 1 纪念一下Python第一题

博客讲述了如何找出在给定区间[l, r]内的2-3整数,即仅由2和3作为质因数的正整数,并分享了使用Python解决此类问题的经历和挑战。" 114437216,5149145,二叉树遍历:前序、中序、后序的Java实现,"['二叉树', '递归算法', 'java']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. 2-3-numbers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A positive integer is called a 2-3-integer, if it is equal to 2x·3y for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 16916 and 108 — are 2-3 integers, while 51021 and 120 are not.

Print the number of 2-3-integers on the given segment [l, r], i. e. the number of sich 2-3-integers t that l ≤ t ≤ r.

Input

The only line contains two integers l and r (1 ≤ l ≤ r ≤ 2·109).

Output

Print a single integer the number of 2-3-integers on the segment [l, r].

Examples
input
Copy
1 10
output
7
input
Copy
100 200
output
5
input
Copy
1 2000000000
output
326
Note

In the first example the 2-3-integers are 123468 and 9.

In the second example the 2-3-integers are 108128144162 and 192.



Python第一步,cf纸尿裤

临时学了一把Python,调的我好苦


# -*- coding: utf-8 -*-
"""
Created on Sun Mar 18 15:55:16 2018

@author: VampireWeekend
"""

import Queue
q=Queue.Queue()

q.put(2)
q.put(3)
l,r=(int(x) for x in raw_input().split())
ceil=2e9
a=[1,2,3]
while not q.empty():
    now=q.get()
#    print a
    if now*2<=ceil and a.count(now*2)==0:
        q.put(now*2)
        a.append(now*2)
    if now*3<=ceil and a.count(now*3)==0:
        q.put(now*3)
        a.append(now*3)
ans=0
for i in a:
    if i>=l and i<=r:
        ans+=1

print ans

to be continued...


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值