思路:

令x为满足2<= a的最大的x。如果a的二进制表示中包含0,则将b构造为(2x+1 - 1) ^ a即可;否则gcd(a ^ b, a & b) = gcd(2x+1 - 1 - b, b) = gcd(2x+1 - 1, b),要令此式最大,b应为(2x+1 - 1)的最大非平凡因子。

实现:

 #include <bits/stdc++.h>
using namespace std; inline int max_fac(int x)
{
for (int i = ; i * i <= x; i++)
{
if (x % i == ) return x / i;
}
return ;
} int main()
{
int q, x;
set<int> st;
for (int i = ; i <= ; i++) st.insert(( << i) - );
while (cin >> q)
{
for (int i = ; i < q; i++)
{
cin >> x;
if (st.count(x))
{
cout << max_fac(x) << endl;
}
else
{
int tmp = , y = x;
while (y) { y >>= ; tmp++; }
cout << ( << tmp) - << endl;
}
}
}
return ;
}

CF1110C Meaningless Operations的更多相关文章

  1. CF1110C Meaningless Operations(构造题)

    这可能是我打那么多次CF比赛时,做出来的最难的一道题了……而且这题也是个绝世好题…… 题目链接:CF原网  洛谷 题目大意:$q$ 组询问,每次给定 $a$ 询问 $\gcd(a\&b,a\o ...

  2. C. Meaningless Operations Codeforces Global Round 1 异或与运算,思维题

    C. Meaningless Operations time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. 【Codeforces Global Round 1 C】Meaningless Operations

    [链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...

  4. CF - 1110 C Meaningless Operations

    题目传送门 题解: 首先根据观察,很容易发的是: x != (1<<k) - 1 时候 答案就是, 将x二进制下再最高位后的0都变成1. 然后就是考虑 x == (1<<k) ...

  5. CF-1110C-Meaningless Operations

    题意: 输入q,然后输入q个a,对于每个a,找到一个b,使gcd(a ^ b, a & b)最大,输出这个最大的gcd: 思路: 用k表示a二进制最高位的二进制编号,1,2,4,8对应1,2, ...

  6. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  7. CodeForces Contest #1110: Global Round 1

    比赛传送门:CF #1110. 比赛记录:点我. 涨了挺多分,希望下次还能涨. [A]Parity 题意简述: 问 \(k\) 位 \(b\) 进制数 \(\overline{a_1a_2\cdots ...

  8. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  9. CF-1110 (2019/02/08)

    CF-1110 A. Parity 快速幂的思想,考虑最后一位即可 #include <bits/stdc++.h> using namespace std; typedef long l ...

随机推荐

  1. BZOJ_2850_巧克力王国_KDTree

    BZOJ_2850_巧克力王国_KDTree Description 巧克力王国里的巧克力都是由牛奶和可可做成的.但是并不是每一块巧克力都受王国人民的欢迎,因为大家都不喜 欢过于甜的巧克力.对于每一块 ...

  2. 「USACO13MAR」「LuoguP3080」 牛跑The Cow Run (区间dp

    题目描述 Farmer John has forgotten to repair a hole in the fence on his farm, and his N cows (1 <= N ...

  3. APIO2015巴厘岛的雕塑——数位DP

    题目:https://www.luogu.org/problemnew/show/P3646 对于A>1,将答案各位全置1,然后从高位到低位改成0判断是否可行: 用f[i][j]数组代表前i个数 ...

  4. pcieport 0000:00:1c.5: PCIe Bus Error

    进入Linux系统 root身份 编辑/etc/default/grub GRUB_CMDLINE_LINUX_DEFAULT="quiet" 将quiet改为 pci=nomsi ...

  5. ceph学习之PG

    PG的计算公式: 整个集群PG的计算公式 Total PGs = ((Total_number_of_OSD * ) / max_replication_count) 每个POOL中PG的计算公式: ...

  6. 64位windows7下安装python,配置numpy和matplotlib库

    一.Python的安装 1.下载python2.7,下载地址:http://www.python.org/,选择系统相应版本,我选择是的是python2.7.6 . python-2.7.6rc1.a ...

  7. D - Opponents

    Description Arya has n opponents in the school. Each day he will fight with all opponents who are pr ...

  8. Identity Server 4 原理和实战(完结)_----选看 OpenId Connect 简介

    Identity Procider:身份提供商

  9. Spring Boot 学习系列(09)—自定义Bean的顺序加载

    此文已由作者易国强授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. Bean 的顺序加载 有些场景中,我们希望编写的Bean能够按照指定的顺序进行加载.比如,有UserServ ...

  10. 洛谷 - P2424 - 约数和 - 整除分块

    https://www.luogu.org/problemnew/show/P2424 记 \(\sigma(n)\) 为n的所有约数之和,例如 \(\sigma(6)=1+2+3+6=12\) . ...