【Codeforces Global Round 1 C】Meaningless Operations
【链接】 我是链接,点我呀:)
【题意】
给你一个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 zero
out.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());
}
}
}
【Codeforces Global Round 1 C】Meaningless Operations的更多相关文章
- 【Codeforces Global Round 1 E】Magic Stones
[链接] 我是链接,点我呀:) [题意] 你可以把c[i]改成c[i+1]+c[i-1]-c[i] (2<=i<=n-1) 问你能不能把每一个c[i]都换成对应的t[i]; [题解] d[ ...
- 【 Codeforces Global Round 1 B】Tape
[链接] 我是链接,点我呀:) [题意] x轴上有m个连续的点,从1标号到m. 其中有n个点是特殊点. 让你用k段区间将这n个点覆盖. 要求区间的总长度最小. [题解] 一开始假设我们需要n个胶带(即 ...
- 【Codeforces Global Round 1 A】Parity
[链接] 我是链接,点我呀:) [题意] 给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数 [题解] 模拟一下转换的过程,加乘的时候都记得对2取余就好 [代码] im ...
- 【Codeforces Beta Round #45 D】Permutations
[题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...
- 【Codeforces Beta Round #88 C】Cycle
[Link]:http://codeforces.com/problemset/problem/117/C [Description] 问你一张图里面有没有一个三元环,有的话就输出. [Solutio ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
随机推荐
- 让DIV在屏幕上下左右居中
转自:http://blog.sina.com.cn/s/blog_65d41dff0100v0iz.html 其实解决的思路是这样的:首们需要position:absolute;绝对定位.而层的定位 ...
- CodeForces - 556D
D. Case of Fugitive time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- [LibreOJ NOIP Round #1] 旅游路线
[题目链接] https://loj.ac/problem/539 [算法] 首先 , 我们用f[u][k]表示现在在景点u ,还有k元钱 , 最多能够走多少路 不难发现f[u][k] = max{ ...
- P1402 酒店之王 网络流
大水题,我自己瞎做就做出来了,没啥说的,zz建图,就是板子. 题干: 题目描述 XX酒店的老板想成为酒店之王,本着这种希望,第一步要将酒店变得人性化.由于很多来住店的旅客有自己喜好的房间色调.阳光等, ...
- Appium + python - weixin公众号操作
from appium import webdriverfrom time import sleep desired_caps = { "platformName":"A ...
- Akka源码分析-Actor发消息(续)
上一篇博客我们分析道mailbox同时也是一个forkjointask,run方法中,调用了processMailbox处理一定数量的消息,然后最终调用dispatcher的registerForEx ...
- @RequestParam 和 @RequestBody 接受的时间格式
这两个接受的时间格式不相同 首先看一下他们的区别 @RequestParam用来处理Content-Type: 为 application/x-www-form-urlencoded编码的内容.(Ht ...
- jQueryTools-Scrollable.js
转载一篇例子,学习使用: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http: ...
- 关于linux下的.a文件与 .so 文件
连续几天终于将一个又一个问题解决了,这里说其中一个问题 描述问题:使用多线程pthread的时候,(我用的IDE,CODEBOLCKS)编译后发现直接弹出窗口,程序还没有被Build..巴拉巴拉,然后 ...
- mysql索引的操作
一.创建和查看普通索引 这是最基本的索引类型,而且它没有唯一性之类的限制 1.创建表时创建普通索引 CREATE TABLE table_name( 属性名 数据类型, ... 属性名 数据类型, I ...