Multiple Gift(AtCoder-3731)

Problem Description

As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below:

A consists of integers between X and Y (inclusive).
For each 1≤i≤|A|−1, Ai+1 is a multiple of Ai and strictly greater than Ai.
Find the maximum possible length of the sequence.

Constraints

  • 1≤XY≤1018
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

X Y

Output

Print the maximum possible length of the sequence.

Example

Sample Input 1

3 20

Sample Output 1

3
The sequence 3,6,18 satisfies the conditions.

Sample Input 2

25 100

Sample Output 2

3

Sample Input 3

314159265 358979323846264338

Sample Output 3

31

题意:给出 x、y 两个数,在 x~y 范围内构造一个序列,要求第 a[i+1] 个数是第 i 个数的倍数,求序列最大的可能的长度

思路:

通过题意可知,按:x、2x、4x、8x、16x、...、2^(i-1) x 的规则构造的序列一定是最长的

因此,只要枚举 i 求出第一个大于 2^(i-1) x 的数时,i-1 就是答案

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 8000+5;
const int dx[] = {-1,1,0,0,-1,-1,1,1};
const int dy[] = {0,0,-1,1,-1,1,-1,1};
using namespace std;

int main(){
    LL x,y;
    scanf("%lld%lld",&x,&y);
    for(LL i=0;i<100;i++){
        LL temp=pow(2,i-1)*x;
        if(temp>y){
            printf("%lld\n",i-1);
            break;
        }
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值