传送门:http://codeforces.com/contest/1081/problem/E

E. Missing Numbers

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Chouti is working on a strange math problem.

There was a sequence of nn positive integers x1,x2,…,xnx1,x2,…,xn, where nn is even. The sequence was very special, namely for every integer ttfrom 11 to nn, x1+x2+...+xtx1+x2+...+xt is a square of some integer number (that is, a perfect square).

Somehow, the numbers with odd indexes turned to be missing, so he is only aware of numbers on even positions, i.e. x2,x4,x6,…,xnx2,x4,x6,…,xn. The task for him is to restore the original sequence. Again, it's your turn to help him.

The problem setter might make mistakes, so there can be no possible sequence at all. If there are several possible sequences, you can output any.

Input

The first line contains an even number nn (2≤n≤1052≤n≤105).

The second line contains n2n2 positive integers x2,x4,…,xnx2,x4,…,xn (1≤xi≤2⋅1051≤xi≤2⋅105).

Output

If there are no possible sequence, print "No".

Otherwise, print "Yes" and then nn positive integers x1,x2,…,xnx1,x2,…,xn (1≤xi≤10131≤xi≤1013), where x2,x4,…,xnx2,x4,…,xn should be same as in input data. If there are multiple answers, print any.

Note, that the limit for xixi is larger than for input data. It can be proved that in case there is an answer, there must be a possible sequence satisfying 1≤xi≤10131≤xi≤1013.

Examples
input

Copy
6
5 11 44
output

Copy
Yes
4 5 16 11 64 44
input

Copy
2
9900
output

Copy
Yes
100 9900
input

Copy
6
314 1592 6535
output

Copy
No
Note

In the first example

  • x1=4x1=4
  • x1+x2=9x1+x2=9
  • x1+x2+x3=25x1+x2+x3=25
  • x1+x2+x3+x4=36x1+x2+x3+x4=36
  • x1+x2+x3+x4+x5=100x1+x2+x3+x4+x5=100
  • x1+x2+x3+x4+x5+x6=144x1+x2+x3+x4+x5+x6=144

All these numbers are perfect squares.

In the second example, x1=100x1=100, x1+x2=10000x1+x2=10000. They are all perfect squares. There're other answers possible. For example, x1=22500x1=22500 is another answer.

In the third example, it is possible to show, that no such sequence exists.

题意概括:

给出 N/2 个 偶数位的数,需要补充剩余 N/2 个奇数位的数,使得 每一位的前缀和都是完全平方数。

如果存在解,按顺序输出 N 个完整数字。

解题思路:

从第一位开始构造前缀和,如果按照实际的数的范围去枚举 x(1e13)肯定会爆炸,那么就折半枚举√x,判断当前前缀和 Si 是否为完全平方数,

如果是则记录下来,并且从 √Si + 1开始枚举求解下一个前缀和。

如果超过的 √Smax ,说明无解。

AC code:

 #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std; const int MAXN = 1e5+;
const LL MAXW = ; LL b[MAXN], a[MAXN]; bool check(LL x)
{
LL y = sqrt(x);
if(y*y == x) return true;
return false;
} int main()
{
int N;
LL sum = ;
scanf("%d", &N);
for(int i = ; i <= N/; i++){
scanf("%I64d", &a[i]);
} LL tmp = 1LL;
while(!check(tmp*tmp+a[])){
tmp++;
if(tmp >= MAXW){
puts("No");
return ;
}
}
b[] = tmp*tmp;
b[] = a[];
int cnt = ;
tmp = sqrt(tmp*tmp+a[]); for(int i = ; i <= N/; i++){
if(tmp >= MAXW){
puts("No");
return ;
}
sum = tmp;
tmp++;
while(!check(tmp*tmp+a[i])){
tmp++;
if(tmp >= MAXW){
puts("No");
return ;
}
}
b[++cnt] = tmp*tmp - sum*sum;
b[++cnt] = a[i];
tmp = sqrt(tmp*tmp + a[i]);
printf("a:%I64d tmp:%I64d\n",a[i], tmp);
}
puts("Yes");
for(int i = ; i <= cnt; i++)
printf("%I64d ", b[i]); return ;
}

Avito Cool Challenge 2018 E. Missing Numbers 【枚举】的更多相关文章

  1. Avito Cool Challenge 2018 :E. Missing Numbers

    E. Missing Numbers 题目链接:https://codeforces.com/contest/1081/problem/E 题意: 现在有n个数(n为偶数),但只给出a2,a4.... ...

  2. Codeforces Avito Code Challenge 2018 D. Bookshelves

    Codeforces Avito Code Challenge 2018 D. Bookshelves 题目连接: http://codeforces.com/contest/981/problem/ ...

  3. Avito Cool Challenge 2018

    考挂了.. A - Definite Game 直接看代码吧. #include<cstdio> #include<cstring> #include<algorithm ...

  4. Avito Cool Challenge 2018(div1+2)

    A. Definite Game: 题意:输入N,输出最小的结果N-x,其中x不少N的因子. 思路:N=2时,输出2:其他情况输出1:因为N>2时,N-1不会是N的因子. #include< ...

  5. Avito Cool Challenge 2018 Solution

    A. Definite Game 签. #include <bits/stdc++.h> using namespace std; int main() { int a; while (s ...

  6. Avito Cool Challenge 2018 自闭记

    A:n==2?2:1. #include<iostream> #include<cstdio> #include<cmath> #include<cstdli ...

  7. Avito Code Challenge 2018 C

    C. Useful Decomposition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  8. Avito Code Challenge 2018 A~E

    A. Antipalindrome 还以为是什么神dp结果就是分情况讨论啊 原串是一串一样的字符的话输出0,是回文串的话输出n-1,否则直接输出原串长度 #include<iostream> ...

  9. cf掉分记——Avito Code Challenge 2018

    再次作死的打了一次cf的修仙比赛感觉有点迷.. 还好掉的分不多(原本就太低没法掉了QAQ) 把会做的前三道水题记录在这.. A: Antipalindrome emmmm...直接暴力枚举 code: ...

随机推荐

  1. 阿里云两台服务器之间拷贝文件命令scp

    参考:云栖社区 不同的Linux之间copy文件通常有4种方法 1.ftp 2.samba服务 3.sftp 4.scp 最简单的方法就是scp,可以理解为ssh管道下的cp命令 把当前一个文件cop ...

  2. Android 屏蔽recent task 按钮

    Step 1 Add this permission to the manifest.xml file <uses-permission android:name="android.p ...

  3. nodejs获取客户机ip

    /** * Created by chaozhou on 2015/11/24. */ var getIp = function(req){ var ipStr = req.headers['x-fo ...

  4. 一个Json、数组、Dictionary转换和数组对比的C#实例

    最近做了一个程序,里面一段代码用到Json.数组.Dictionary转换和数组对比的一些知识,虽然在实际碰到类似问题时候有更好的方法,但这就当是一次基础知识的回顾,现在分享一下. 先介绍下要实现的业 ...

  5. Java基础(五)面对对象

    一.面向对象 面向对象 : 就是一种编程思想 1.类和对象 类是指描述一类事物,或者看成是一个分类,可以把类看作构造对象的模板. 对象是指具体的个体(也叫实例-instance).创建对象使用 new ...

  6. javaweb之MVC设计模式

    1.MVC简介 MVC是Model-View-Controller的简称,即模型-视图-控制器.MVC是一种设计模式,它把应用程序分成三个核心模块:模型,视图,控制器,它们各自处理自己的任务. 模型( ...

  7. C++中细节知识点

    C++中常识小知识: 1.在C++的类中成员变量与成员函数默认为私有的,结构体中的成员变量与成员函数默认为公有的. 2.C++中this关键字是指针,指向当前对象. 3.在C++中一般类的成员变量与成 ...

  8. java IO流实现删除文件夹以及文件夹中的内容

    这篇主要是对IO文件流对文件常用处理中的删除文件夹,平时我们直接删除文件夹既可以删除里面的全部内容. 但是java在实现删除时,只能是文件才会被删除. 所以这里需要定义一个方法,来递归调用方法(递归调 ...

  9. js基本数据类型和引用类型的区别详解-笔记

    原文参考http://mp.weixin.qq.com/s/apFyUgqT5N-bsDUjP4Eryg 笔记总结 首先记住js中的基础数据类型undefined,null,boolean,strin ...

  10. 子div设置float后会导致父div无法自动撑开

    本文是从简书复制的, markdown语法可能有些出入, 想看"正版"和更多内容请关注 简书: 小贤笔记 注: 文章部分转载 彩泉 - 博客园 原因:内部的DIV因为float:l ...