【链接】 我是链接,点我呀:)
【题意】

给你一个a
让你从1..a-1的范围中选择一个b
使得gcd(a^b,a&b)的值最大

【题解】

显然如果a的二进制中有0的话。
那么我们就让选择的b的二进制中对应的位置为1
剩下全为0就好
这样a的二进制全都变成1之后就是答案了(gcd的右边是0)。
但是如果a的二进制里面全是1的话。
就没办法这么构造了
这里有两种情况。
①.1的个数是偶数
那么就101010这样构造
另外一个数就是010101
答案就是010101转换成十进制
②.1的个数是奇数
找不出来规律。。然后就打表了。
(就25个数字>_<)

【代码】

import java.io.*;
import java.util.*;public class Main {static int N = 100;static InputReader in;static PrintWriter out;static int a,q;static int bin[];public static void main(String[] args) throws IOException{in = new InputReader();out = new PrintWriter(System.out);bin = new int[N+10];q = in.nextInt();for (int i = 1;i <= q;i++) {a = in.nextInt();int num = 0,cnt1 = 0;int cur = 1;while (a>0){cur = cur*2;num++;if (a%2==1) {cnt1++;}a/=2;}if (num!=cnt1){//exsit zeroout.println(cur-1);}else {if(num%2==1) {switch(num) {case 3:out.println(1);break;case 5:out.println(1);break;case 7:out.println(1);break;case 9:out.println(73);break;case 11:out.println(89);break;case 13:out.println(1);break;case 15:out.println(4681);break;case 17:out.println(1);break;case 19:out.println(1);break;case 21:out.println(299593);break;case 23:out.println(178481);break;case 25:out.println(1082401);break;}}else {cur = 1;int ans = 0;for (int j = 1;j <= num;j++) {if (j%2==1) {ans = ans + cur;}cur*=2;}out.println(ans);}}}out.close();}static class InputReader{public BufferedReader br;public StringTokenizer tokenizer;public InputReader() {br = new BufferedReader(new InputStreamReader(System.in));tokenizer = null;}public String next(){while (tokenizer==null || !tokenizer.hasMoreTokens()) {try {tokenizer = new StringTokenizer(br.readLine());}catch(IOException e) {throw new RuntimeException(e);}}return tokenizer.nextToken();}public int nextInt() {return Integer.parseInt(next());}}
}

转载于:https://www.cnblogs.com/AWCXV/p/10355883.html

【Codeforces Global Round 1 C】Meaningless Operations相关推荐

  1. 【Codeforces Global Round 23】B. Rebellion

    Codeforces Global Round 23中B. Rebellion Codeforces比赛记录 文章目录 题目链接: 一.B. Rebellion 题目意思: 上思路: 总结 B. Re ...

  2. Codeforces Global Round 1 晕阙记

    Codeforces Global Round 1 晕阙记 我做这场比赛的时候晕得要死.做这三道题做太久了,rating涨不起来啊! A 如果愿意的话你可以看做是膜2意义下的运算,写快速幂等各种膜运算 ...

  3. Codeforces Global Round 3

    Codeforces Global Round 3 A. Another One Bites The Dust 有若干个a,有若干个b,有若干个ab.你现在要把这些串拼成一个串,使得任意两个相邻的位置 ...

  4. Codeforces Global Round 14 F. Phoenix and Earthquake 思维 + 并查集

    传送门 文章目录 题意: 思路: 题意: 给你nnn个点,mmm条边,限制xxx,每个点都有沥青aia_iai​,定义合并两个点即两点之间有边且au+av≥xa_u+a_v\ge xau​+av​≥x ...

  5. Codeforces Global Round 1

    Codeforces Global Round 1 题解:The Editorial of the First Codeforces Global Round A:其实mod 2计算一下就行了 B:删 ...

  6. 【CodeForces 1265C --- Beautiful Regional Contest】

    [CodeForces 1265C --- Beautiful Regional Contest] 题目来源:点击进入[CodeForces 1265C - Beautiful Regional Co ...

  7. Codeforces Global Round 4-D. Prime Graph(伯特兰-切比雪夫定理)

    题目:Codeforces Global Round 4-D. Prime Graph 题意:给出n(顶点的个数),要求所得图满足: 1.无平行边和自环 2.边的总数是个质数 3.每个点的度(也就是点 ...

  8. codeforces global round 23

    constest :codeforces global round 23 contest time:2022.10.16 contest grade: 2800 contest rating chan ...

  9. 【CodeForces】Codeforces Global Round 9

    比赛链接 点击打开链接 官方题解 点击打开链接 Problem A. Sign Flipping 将奇数位的数取非正值,偶数位的数取非负值即可. 单组数据时间复杂度 O ( N ) O(N) O(N) ...

  10. 【Codeforces】Codeforces Global Round 18

    题意:可以通过选取下标不同的两个数,使其中一个数的值增加,另一个数的值减小.问:反复操作后高度差最小为? 思路:答案只可能为0或1.当所有数之和能被数字的个数整除时说明通过移动总是可以让高度差为0的. ...

最新文章

  1. Common Subsequence 1159 hdu
  2. .classpath文件
  3. 使用Maven搭建Struts2+Spring3+Hibernate4的整合开发环境
  4. 如何设计一门语言(六)——exception和error code
  5. python数据科学指南是什么_《Python数据科学指南》——导读
  6. 帆软 JAVA扩展_java报表开发工具FineReport教程之报表设计:单元格扩展
  7. 草珊瑚理解IFC(inline formatting context)
  8. Nginx配置https和wss
  9. Spring MVC中静态资源加载
  10. English Through Movie
  11. 经典sql练习题(oracle版)
  12. 形容计算机技术发展的词,形容技术发展的成语是什么_四字词语 - 成梦词典
  13. 线程数据共享:pthread_getspecific和pthread_setspecific
  14. 学习mysql比较好一些书籍
  15. 金额数字转换成大写,英文。111,壹佰壹拾壹元整,one hundred and eleven yuan
  16. 为什么说衰老先从血管开始?
  17. uni-app中picker组件的“取消”“完成”国际化,能变成英文
  18. 电脑开机提示 EFI PXE 0 for IPv6
  19. OpenCV - GrabCut 算法抠图(Python实现)
  20. 为什么Mendix重视私有化部署

热门文章

  1. Glide 4.x之请求网络图片数据流程解析
  2. android通用对话框,android-所有活动中的“通用”对话框
  3. 我用Python爬了点你们需要的电影,这些电影真的很不错~
  4. 历时半载,我的新课上线了
  5. TV Metro界面(仿泰捷视频TV版)源码解析
  6. python---windows中的文件路径书写的错误
  7. 服务器接收不到信号,信号(SIGTERM)不被Windows上的subprocess接收
  8. python中哈希是什么意思_python 中倒是什么事可哈希的意思那?
  9. 用matlab给图像加水印,大神,在MATLAB中将图像水印插入音频文件可否给我个具体的步骤啊!很着急​...
  10. 查看工作日志Linux,工作日志,Linux的表现还是不错的