当前位置: 首页 > news >正文

桂林企业建站产品宣传网站模板

桂林企业建站,产品宣传网站模板,徐州东站,登陆到wordpressCF1790E Vlad and a Pair of Numbers 题解题目链接字面描述题面翻译题目描述输入格式输出格式样例 #1样例输入 #1样例输出 #1思路代码实现题目 链接 https://www.luogu.com.cn/problem/CF1790E 字面描述 题面翻译 共有 ttt 组数据。 每组数据你会得到一个正整数 xxx&…

CF1790E Vlad and a Pair of Numbers 题解

  • 题目
    • 链接
    • 字面描述
      • 题面翻译
      • 题目描述
      • 输入格式
      • 输出格式
      • 样例 #1
        • 样例输入 #1
        • 样例输出 #1
  • 思路
  • 代码实现

题目

链接

https://www.luogu.com.cn/problem/CF1790E

字面描述

题面翻译

共有 ttt 组数据。

每组数据你会得到一个正整数 xxx,你需要构造一组正整数 aaabbb,满足:

  • a+b=x×2a + b = x \times 2a+b=x×2

  • axor⁡b=xa \operatorname{xor} b = xaxorb=x,其中 xor⁡\operatorname{xor}xor 指异或。

输出你构造的 aaabbb。如有多解,任意输出一解即可。如无解,输出 −1-11

1≤t≤1041 \leq t \leq 10^41t1041≤x≤2291 \leq x \leq 2^{29}1x229。同时,你需要保证你构造的 aaabbb 满足 1≤a,b≤2301 \leq a,b \leq 2^{30}1a,b230

题目描述

Vlad found two positive numbers $ a $ and $ b $ ( $ a,b>0 $ ). He discovered that $ a \oplus b = \frac{a + b}{2} $ , where $ \oplus $ means the bitwise exclusive OR , and division is performed without rounding…

Since it is easier to remember one number than two, Vlad remembered only $ a\oplus b $ , let’s denote this number as $ x $ . Help him find any suitable $ a $ and $ b $ or tell him that they do not exist.

输入格式

The first line of the input data contains the single integer $ t $ ( $ 1 \le t \le 10^4 $ ) — the number of test cases in the test.

Each test case is described by a single integer $ x $ ( $ 1 \le x \le 2^{29} $ ) — the number that Vlad remembered.

输出格式

Output $ t $ lines, each of which is the answer to the corresponding test case. As the answer, output $ a $ and $ b $ ( $ 0 < a,b \le 2^{32} $ ), such that $ x = a \oplus b = \frac{a + b}{2} $ . If there are several answers, output any of them. If there are no matching pairs, output -1.

样例 #1

样例输入 #1

6
2
5
10
6
18
36

样例输出 #1

3 1
-1
13 7
-1
25 11
50 22

思路

根据题目 a+b=2x和aa+b=2x和aa+b=2xa xorxorxor b=xb=xb=x

我们能发现一个非常高重要的突破点a异或b流失了xa异或b流失了xa异或b流失了x
a按位与b=x/2a按位与b=x/2a按位与b=x/2
∵题目可输出任意解
a=x/2,b=x+x/2a=x/2,b=x+x/2a=x/2,b=x+x/2

但我们还要考虑一个无解的情况:
当x是奇数时,无法被2整除,无解
(x/2)按位与x!=0(x/2)按位与x!=0(x/2)按位与x!=0,有误,无解

OK,过程理完,上代码

代码实现

#include<bits/stdc++.h>
using namespace std;int t,n; 
int main(){scanf("%d",&t);while(t--){scanf("%d",&n);if(n%2==1){printf("-1\n");continue;}if(((n/2)&n)!=0){printf("-1\n");continue;}printf("%d %d\n",n/2,n/2+n);}return 0;
} 
http://www.yayakq.cn/news/239004/

相关文章:

  • 四川省城乡和住房建设厅网站首页网站推广流程
  • 宜昌网站建设开发建设公司网站方案
  • 学生没钱怎么开网店网站排名优化制作
  • 网站建设算什么行业网站源码超市 下载
  • 手工艺品外贸出口公司网站建设方案html表格菜鸟教程
  • 李家沱网站建设手机商城网站建设策划方案范文
  • 企业为什么要建站台呢东莞优化公司首选3火星
  • 山东电力建设网站怀柔网站建设优化seo
  • 手机设置管理网站首页黑龙seo网站优化
  • 重庆网站建设接重庆零臻科技网站开发 估算 excel
  • 网页网站设计公司排行榜各大企业邮箱
  • wordpress下载网站模板怎么用广告设计用的软件
  • 注册网站要多少钱一年怎样做网站导购
  • 网站侧导航应用数据库网站开发
  • 用邮箱做网站图书馆网站开发策划书
  • 公司网站php建设厅焊工证查询官网
  • 学网站开发技术十大平面设计公司
  • 苏州网站建设名字ppt免费模板官网
  • 手机移动端网站怎么做的apmserv搭建网站
  • 用来做区位分析的地图网站附近的装修公司地点
  • 单位 内网网站建设邯郸网络运营中心电话
  • 怎样给自己建立网站黄江仿做网站
  • 第三方网站下载素材是怎么做WordPress添加防盗链接
  • 上海广告传媒有限公司网站优化有前途吗
  • 无代码网站建设怎么在ftp看网站后台地址
  • 怎么样建设公司网站国家企业信用信息没有网站怎么做
  • 企业网站的开发公司编程除了做网站还能干什么
  • 网站建设与管理实训主要内容wordpress 企业官网
  • 怎样做网站手机和电脑通用宜和购物电视购物官方网站
  • 设计网站页面注意事项抖音代运营怎么跟客户沟通并成交