思路:

令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. <十三>UML核心视图静态视图之业务用例图

    一:uml的核心视图 --->如果说UML是一门语言,上一章学习的参与者等元素是uml的基本词汇,那么视图就是语法.uml通过视图将基元素组织在一起,形成有意义的句子. --->uml可视 ...

  2. python 去停用词

    Try caching the stopwords object, as shown below. Constructing this each time you call the function ...

  3. 再谈使用X.PagedList.Mvc 分页(ASP.NET Core 2.1)

    在以前的博文中写过使用X.PagedList.Mvc组件来对ASP.NET MVC应用程序进行分页,可以参考此篇随笔:Asp.net MVC 使用PagedList(新的已更名 为X.PagedLis ...

  4. Flutter从入门到进阶实战携程网App_汇总贴

    视频地址:https://coding.imooc.com/class/321.html?mc_marking=60e5294c605a87b2af7257d06f70505e&mc_chan ...

  5. JAVA基础--JAVA API常见对象(其他API)13

    一.其他API 1.System类 system类中的方法和成员变量都是静态的, 不需要创建System对象就可以直接使用. /* * 演示System的使用 */ public class Syst ...

  6. E20180506-hm

    更新: 2019/02/19 原来忘记分类,把此博文归入单词类 criterion n. 规范; (批评.判断等的) 标准,准则; criteria  n. (批评.判断等的) 标准,准则( crit ...

  7. Warning: The Copy Bundle Resources build phase contains

    在编译程序时,遇到了这样的Waring:   Warning: The Copy Bundle Resources build phase contains this target's Info.pl ...

  8. win7 mongod不是内部命令

    1.下载MongoDB 1.1 MongoDB下载 1.2 选择Server下面的 Community 2.安装MongoDB 2.1 注意事项:一直下一步就行了,但是遇到下面这个界面,注意一定要去掉 ...

  9. Legacy C++ MongoDB Driver

    https://docs.mongodb.com/ecosystem/drivers/cpp/

  10. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】

    呵呵哒,上分~ CodeForces 724A: 题意: 给你两个星期几,问连续两个月的头一天是否满足: #include <iostream> #include <stdio.h& ...