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≤X≤Y≤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;
}