#include
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define db double
#define Pir pair
#define PIR pair
#define INF 0x3f3f3f3f
#define mod 998244353
int br[10];
int ar[5];
int main()
{
/* fre(); */
int T;
scanf("%d\n", &T);
ar[1] = 8, ar[2] = 4, ar[3] = 2;
while(T --)
{
ll a, b;
scanf("%lld %lld", &a, &b);
if(a < b) swap(a, b);
if(a % b)
{
printf("-1\n");
continue;
}
ll c = a / b;
memset(br, 0, sizeof(br));
for(int i = 1; i <= 3; i ++)
{
while(c % ar[i] == 0)
{
c /= ar[i];
br[ar[i]] ++;
}
}
if(c != 1)
{
printf("-1\n");
continue;
}
printf("%d\n", br[2] + br[4] + br[8]);
}
return 0;
}
#include
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define db double
#define Pir pair
#define PIR pair
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 1e3 + 100;
int ar[mxn];
int br[mxn];
int cr[mxn];
int main()
{
/* fre(); */
int T;
scanf("%d\n", &T);
while(T --)
{
memset(br, 0, sizeof(br));
int n;
scanf("%d\n", &n);
for(int i = 1; i <=n; i ++)
scanf("%d", &ar[i]), br[ar[i]] = 1;
int ans = 0;
for(int i = 1; i <= 1024; i ++)
{
memset(cr, 0, sizeof(cr));
int fg = 1;
for(int j = 1; j <= n; j ++)
{
int t = (ar[j] ^ i);
if(++ cr[t] >= 2)
{
fg = 0;
break;
}
}
if(fg == 0)
continue;
for(int j = 0; j <= 1024; j ++)
{
if(br[j] != cr[j])
{
fg = 0;
break;
}
}
if(fg)
{
ans = i;
break;
}
}
if(ans == 0)
printf("-1\n");
else
printf("%d\n", ans);
}
return 0;
}
000
001
010
011
100
101
#include
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define db double
#define Pir pair
#define PIR pair
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 1e6 + 100;
int main()
{
/* fre(); */
int T;
scanf("%d", &T);
while(T --)
{
ll n, i = 1, ans = 0;
scanf("%lld\n", &n);
ll now = n;
while(now)
{
ans += n / i;
i *= 2;
now >>= 1;
}
printf("%lld\n", ans);
}
return 0;
}
#include
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define db double
#define Pir pair
#define PIR pair
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 1e3 + 100;
int main()
{
/* fre(); */
int T;
scanf("%d\n", &T);
while(T --)
{
ll n, t;
scanf("%lld", &n);
t = n;
ll ct = 0;
while(n)
{
if(n & 1) ct ++;
n >>= 1;
}
printf("%lld\n", t * 2 - ct);
}
return 0;
}
#include
using namespace std;
void fre() { freopen("A.txt", "r", stdin); freopen("Ans.txt","w",stdout); }
void Fre() { freopen("A.txt", "r", stdin);}
#define ios ios::sync_with_stdio(false)
#define Pi acos(-1)
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define db double
#define Pir pair
#define PIR pair
#define INF 0x3f3f3f3f
#define mod 998244353
const int mxn = 1e6 + 100;
vector<int> e[mxn];
vector<int> col[mxn];
vector<int> ans;
int num[mxn];
int main()
{
/* fre(); */
int n, m;
scanf("%d %d", &n, &m);
for(int i = 1, u, v; i <= m; i ++)
{
scanf("%d %d", &u, &v);
e[u].pb(v);
e[v].pb(u);
}
for(int i = 1, t; i <= n; i ++)
{
scanf("%d", &t);
col[t].pb(i);
num[i] = 1; //初始的时候,每个节点周围只有一个 自己1个节点
}
for(int i = 1; i <= n; i ++)
{
for(auto u : col[i])
{
if(num[u] != i) printf("-1\n"), exit(0);
for(auto v : e[u])
if(num[v] == i) num[v] ++;
ans.pb(u);
}
}
for(auto i : ans) printf("%d ", i);
return 0;
}