C. Constructing Tests
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero.

Consider the following problem:

You are given two integers n and m. You have to construct an m-free square matrix of size n × n such that the number of 1's in this matrix is maximum possible. Print the maximum possible number of 1's in such matrix.

You don't have to solve this problem. Instead, you have to construct a few tests for it.

You will be given t numbers x1, x2, ..., xt. For every , find two integers ni and mi (ni ≥ mi) such that the answer for the aforementioned problem is exactly xi if we set n = ni and m = mi.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of tests you have to construct.

Then t lines follow, i-th line containing one integer xi (0 ≤ xi ≤ 109).

Note that in hacks you have to set t = 1.

Output

For each test you have to construct, output two positive numbers ni and mi (1 ≤ mi ≤ ni ≤ 109) such that the maximum number of 1's in a mi-free ni × ni matrix is exactly xi. If there are multiple solutions, you may output any of them; and if this is impossible to construct a test, output a single integer  - 1.

Example
input

Copy
3
21
0
1
output
5 2
1 1
-1

思路

一个n*n的矩阵(由01组成)分成若干个m*m的矩阵,每个m*m的矩阵中0的个数不得小于1.那么每一行都至少有n/m个0,每一列也是至少n/m个0,

可以推出公式   x = n*n - (n/m)*(n/m)  分解可得  x = (n - n.m)*(n + n/m) 然后直接对于x因式分解 设 x = a*b ,a = (n-n/m),b = (n + n/m).然后暴力枚举a,b

由 a + b 可以得出 a + b = 2*n; n/m = sqrt(n*n - x); 则 m = n/sqrt(n*n - x).....根据枚举的ab,看能否求出符合条件的n , m,如果没有的话就输出-1。

实现代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,x;
cin>>n;
while(n--){
cin>>x;
ll flag = ;
if(x==){ cout<<<<" "<<<<endl;continue;}
for(ll i = ;i*i <= x;i++){
if(x%i==){
if((i+x/i)%==) continue;
ll n1 = (i + x/i)/;
ll m = n1*n1 - x;
ll m1 = sqrt(m);
if(m1*m1 != m||n1==||m1==) continue;
if(n1*n1 - (n1/(n1/m1)*(n1/(n1/m1)))!=x) continue;
cout<<n1<<" "<<n1/m1<<endl;
flag = ;
break;
}
}
if(!flag) cout<<-<<endl;
}
return ;
}

Educational Codeforces Round 38 (Rated for Div. 2) C的更多相关文章

  1. Educational Codeforces Round 38 (Rated for Div. 2)

    这场打了小号 A. Word Correction time limit per test 1 second memory limit per test 256 megabytes input sta ...

  2. 【Educational Codeforces Round 38 (Rated for Div. 2)】 Problem A-D 题解

    [比赛链接] 点击打开链接 [题解] Problem A Word Correction[字符串] 不用多说了吧,字符串的基本操作 Problem B  Run for your prize[贪心] ...

  3. Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - C. Magic Ship Time Limit: 2000 mSec P ...

  4. Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems(动态规划+矩阵快速幂)

    Problem   Educational Codeforces Round 60 (Rated for Div. 2) - D. Magic Gems Time Limit: 3000 mSec P ...

  5. Educational Codeforces Round 43 (Rated for Div. 2)

    Educational Codeforces Round 43 (Rated for Div. 2) https://codeforces.com/contest/976 A #include< ...

  6. Educational Codeforces Round 35 (Rated for Div. 2)

    Educational Codeforces Round 35 (Rated for Div. 2) https://codeforces.com/contest/911 A 模拟 #include& ...

  7. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  8. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  9. Educational Codeforces Round 63 (Rated for Div. 2) 题解

    Educational Codeforces Round 63 (Rated for Div. 2)题解 题目链接 A. Reverse a Substring 给出一个字符串,现在可以对这个字符串进 ...

随机推荐

  1. 如何查看Drupal网站使用的模块

    大家在学习使用Drupal的过程中,总喜欢去查看或借鉴那些做得十分优秀的drupal网站,很想知道这个drupal网站使用了哪些模块?其实很简单,已经有人帮我们实现了这个愿望. 那就是DrupalXr ...

  2. sql 两表更新

    UPDATE sale_origin_line set  state='cancel'  from  sale_origin p,sale_origin_line q  where p.id=q.or ...

  3. 添加默认的过滤条件xml

    <search string="Search Sales Origin"> <field name="name"/> <field ...

  4. C++中的this和Python的self对比

    Python,当实例对象调用函数(函数其实都是属于类空间的)的时候,系统会自动将对象本身传入 函数在定义时的第一个变量一般是self.(但self并不是关键字,用其他名字也可以)         定义 ...

  5. Android环境下使用call_usermodehelper()以及调试

    有时候设备驱动需要做一些与其他的设备通信的操作,但是驱动本身又不可以去实作,那这个时候就可以通过调用用户态的软件,通过这个软件和其他的设备进行通信. 那在内核态如何去调用用户态的程序呢?call_us ...

  6. 使用 vi/vim 时,粘贴进新创建文件或空文件的首行内容丢失的解决方法

    只需要进入插入模式后,回车空一行或几行,再粘贴,再把上面的几个空行back回去,就不会丢失首行的内容了.

  7. 8、Dockerfile介绍和最佳实践

    一.Dockerfile 概念 1.Dockerfile是什么 Docker 镜像是一个特殊的文件系统,除了提供容器运行时所需的程序.库.资源.配置等文件外,还包含了一些为运行时准备的一些配置参数(如 ...

  8. 浅谈android Service和BroadCastReceiver

    1.题记 Android中的服务和windows中的服务是类似的东西,服务一般没有用户操作界面,它运行于系统中不容易被用户发觉,可以使用它开发如监控之类的程序. 广播接收者(BroadcastRece ...

  9. cocos2dx内存优化

    纹理消耗了大量内存 在大部分情况下,是纹理(textures)消耗了游戏程序大量的内存.因此,纹理是我们首要考虑优化的对象 纹理加载 cocos2d里面纹理加载分为两个阶段:从图片文件中创建一个Ima ...

  10. openstack删除僵尸卷

    问题描述: 最近在清理openstack环境,在删除cinder云硬盘时,一直发现有两个卷在删除中. 解决方法如下: 首先我们去cinder的数据库中找到这个卷,命令为: MariaDB [(none ...