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. mysqldump: Got error: 1356 mysqldump的重要参数--force

    一个MySQL的备份突然变小了很多,但实际的数据量却一直在增长.备份脚本也没有调整过.为什么呢? 重现了一下备份过程,发现备份中遇到了如下错误: mysqldump: Got error: 1356: ...

  2. MiZ702学习笔记10——文本实例化IP的方法

    之前,添加vivado自带IP的时候,都是以图形化的方式:一般是新建一个Block Design顶层文件,然后将图形化的ip贴到,Block Design中. 但是,在进行PL的开发过程中,有时不想使 ...

  3. 一段程序的分析——C++析构器,何时析构

    最近在看小甲鱼的视频,有段程序是这么写的: #include <iostream> #include <string> class Pet { public: Pet(std: ...

  4. matplotlib 雷达图2

    说明 搞了一个最新版本的雷达图,比以前那个美观. 不多说,代码奉上: 完整代码 ''' matplotlib雷达图 ''' import numpy as np import matplotlib.p ...

  5. CF708D Incorrect Flow

    CF708D Incorrect Flow 有源汇上下界最小费用可行流.(= =) 对每条给定的边连边: 首先\(f_i\)是给定的,所以要有一条这个边而且要流满,先\(a_i-b_i\)连一条上下界 ...

  6. SQLServer数据库还原:无法在已有的mdf文件上还原文件

    如果提示无法在已有的mdf文件上还原文件,请修改如下位置

  7. jqGrid 列内容超过一定长度省略表示

    jqgrid初始化方法中的,对应列添加formatter方法 colNames : [ "描述" ], colModel : [ { name : 'description', i ...

  8. markdown 笔记二

    Markdown 语法笔记==============================1,头部欢迎# 欢迎使用flaskBlog ------ flask对于我来说,适合快速开发一些小网页,自己也想整 ...

  9. Jmeter(十二)_打印时间戳

    Jmeter中提供了一种函数,可以打印时间戳,如下图 年: yyyy 月:MM 日:dd 时: HH 分: mm 秒:ss 关于时间戳的格式,可以自由组合定义,这里我写成这样 yyyy-MM-dd H ...

  10. 微信小程序获取客户端系统信息

    微信小程序中有个API: wx.getSystemInfo() 可以获取系统的信息 wx.getSystemInfoSync()===>同步获取系统信息 wx.getSyatemInfo({ s ...