目录
A. Johnny and Ancient Computer
C. Johnny and Another Rating Drop
A. Johnny and Ancient Computer
题意:给定两个数A,B,问A能不能不断通过乘或除2、4、8(能整除才能除),得到B
思路:如果A能得到B,B也能得到A,所以AB的大小关系假定为A大B小。如果A不能整除B,则不可能得到B,否则计算出AB倍数,为了让步数最小先除8再除4再除2,如果最后剩的数非1,则也不能得到B。
AC代码:
/*---------------------------------
*File name: A.cpp
*Creation date: 2020-06-05 09:18
*Link:https://codeforces.com/contest/1362/problem/A
*-------------------------------*/
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define LL long long
#define PII pair<int, int>
#define Pque priority_queue
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const double EPS = 1e-8;
int main(){
int t;
scanf("%d", &t);
while(t--){
LL a , b;
scanf("%lld %lld", &a, &b);
LL ans = 0;
if(a < b) swap(a, b);
if(a % b != 0) printf("-1\n");
else {
LL times = a / b;
while(times % 8 == 0) times /= 8, ans++;
while(times % 4 == 0) times /= 4, ans++;
while(times % 2 == 0) times /= 2, ans++;
if(times != 1) printf("-1\n");
else printf("%lld\n", ans);
}
}
return 0;
}
B. Johnny and His Hobbies
题意:给定n个各不相同的数集,问能不能选择一个K,使得每个数异或K之后的数集与原数集