AtCoder ARC088C Multiple Gift

C - Multiple Gift


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

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 1i|A|1Ai+1 is a multiple of Ai and strictly greater than Ai.

Find the maximum possible length of the sequence.

Constraints

  • 1XY1018
  • 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.


Sample Input 1

Copy
3 20

Sample Output 1

Copy
3

The sequence 3,6,18 satisfies the conditions.


Sample Input 2

Copy
25 100

Sample Output 2

Copy
3

Sample Input 3

Copy
314159265 358979323846264338

Sample Output 3

Copy
31

题目大意:构造一个数列,要求所有项都在[x,y]之间,要求每一项必须能整除之前的所有项。

思路:一开始我想的模拟,第一个数很明显就是x,然后选择最后一个数去看能不能整除前面的,如果可以那么就把最后一个数*2当作新的数,否则就*剩下没能整除的部分。然后爆炸,siy死也过不了第一个样例。

后来选择找规律。log2((r-l)/l)+1,不过,WA18,就开始“调参”,log2((r-l+1)/l)+1,log2((r-l)/l+1)+1......

总是WA18让我觉得有点不大对劲。

手动求log。

A了。

貌似是精度的问题。

以后再也不log了。

附代码。

#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<map>
#include<queue>
#include<vector>
#include<stack>
#include<set>
#define pa pair<int,int>
#define INF 0x3f3f3f3f
#define inf 0x3f
#define fi first
#define se second
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back
#define pause system("pause")

using namespace std;

inline ll read()
{
    long long f=1,sum=0;
    char c=getchar();
    while (c<'0' || c>'9')
    {
        if (c=='-')	f=-1;
        c=getchar();
    }	
    while (c>='0' && c<='9')
    {
        sum=sum*10+c-'0';
        c=getchar();
    }
    return sum*f;
}
int main()
{
	ll l=read(),r=read();
	int ans=0;
	while (r>=l) l*=2,ans++; 
	cout<<ans;
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值