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. HDU 1269 迷宫城堡(判断有向图强连通分量的个数,tarjan算法)

    迷宫城堡 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. Python中 __init__的通俗解释?附修饰器contextmanager的理解

    作者:匿名用户链接:https://www.zhihu.com/question/46973549/answer/103805810来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请 ...

  3. 查看历史命令 history

    生产上有文件被清空了,想查查是谁操作的? 通过history查看历史命令: $history |more 也可以通过文件查看历史命令: $vi ~/.bash_history 只显示历史命令,像查一查 ...

  4. 20155211 Exp4 恶意代码分析

    20155211 Exp4 恶意代码分析 实践目标 1 监控你自己系统的运行状态,看有没有可疑的程序在运行. 2 是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或 ...

  5. 20155218《网络对抗》Exp3 免杀原理与实践

    20155218<网络对抗>Exp3 免杀原理与实践 一.使用msf生成后门程序的检测 (1)将上周msf生成的后门文件放在virscan.org中进行扫描,截图如下: (2)使用msf时 ...

  6. python 回溯法 子集树模板 系列 —— 3、0-1背包问题

    问题 给定N个物品和一个背包.物品i的重量是Wi,其价值位Vi ,背包的容量为C.问应该如何选择装入背包的物品,使得放入背包的物品的总价值为最大? 分析 显然,放入背包的物品,是N个物品的所有子集的其 ...

  7. sqlyog mysql 外键引用列找不到想要的字段的原因

    这是因为引用列必须为一个主键才行

  8. PowerBI开发 第五篇:关系和交互

    PowerBI 使用 内存的列式数据库 VertiPaq,用于对已发布的数据集进行数据压缩和快速处理,能够使PowerBI报表执行脱机访问,面向列的处理,高度优化对1:N关系的处理性能.关系是数据分析 ...

  9. 浅谈String模块ascii_letters和digits

    本文介绍string模块ascii_letters和digits方法,其中ascii_letters是生成所有字母,从a-z和A-Z,digits是生成所有数字0-9. 示例如下: In [2]: c ...

  10. Web项目开发流程 PC端

      一.了解.明确需求. 这个应该是第一步了,不了解需求你就不知道为什么要做,要怎么去做这个项目的工作. (1)明确需求是相当重要的,很有必要去和产品经理.设计人员去沟通,需要明白每一个按钮,每一个开 ...