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. day05今日学习总结:字符串类型

    昨日学习复习: 数据类型: 有序.无序 有序:可以根据索引查找的数据 可变不可变 可变:在值变的情况下,id不变,证明原值是在改变的 不可变:在值变的情况下,id也跟着变,证明不是在改原值. 今日学习 ...

  2. DRUPAL7 : 安装中文版本时遇到的问题

    http://yeenav.com是基于Drupal 7+汉化资源 搭建. 期间遇到一些麻烦, 做个记录. 首先把语言包drupal-7.0.zh-hans.po 放在htdocs/drupal-7. ...

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

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

  4. C++中前置声明介绍

    前置声明是指对类.函数.模板或者结构体进行声明,仅仅是声明,不包含相关具体的定义.在很多场合我们可以用前置声明来代替#include语句. 类的前置声明只是告诉编译器这是一个类型,但无法告知类型的大小 ...

  5. React学习-React初识

    一.前言 为什么要去学习React呢,关于前端三大框架Angular,Vue,React其实都得去学吧,因为大家都在用啊,大家都再谈论啊,面试什么的都要求,没办法,曾几何时,大家都说求求大佬们别坑新了 ...

  6. 结对编程--C语言子程序词法分析

    一.问题描述 C语言小子集表的定义 2.设计单词属性值,各类表格(表示标识符表.常量表),单词符号及机内表示,采用标准输入和输出的方式.程序从键盘接收代码,遇到代码结束符"#"时结 ...

  7. ASP.NetCore2.0概览

      微软为了统一微软平台,造就了.netStandard,不管之前的Framework还是最新的.netCore都必须支持.netStandard标准来统一各个平台的开发api. 以下是之前的微软各个 ...

  8. 【zigbee 】2.4G信号发放器 AT2401C PA功放

    概述 AT2401C 是一款面向Zigbee,无线传感网络以及其他2.4GHz 频 段无线系统的全集成射频功能的射频前端单芯片.AT2401C 是采用 CMOS 工艺实现的单芯片器件,其内部集成了功率 ...

  9. Android 使用 OnTouchListener 接口监听双击或多击事件

    这里是使用 OnTouchListener 实现的监听双击 or 多击的监听器.通过 View.setOnTouchListener ,可以实现在任意 View 上监听双击事件. 网上有许多文章简单的 ...

  10. 【Beta阶段】第二次Scrum Meeting!

    每日任务内容: 本次会议为第二次Scrum Meeting会议~ 由于本次会议项目经理召开时间较晚,所以在公寓7层召开,所以女生没来…召开时间大家集会10分钟,经理与后端探讨20分钟. 队员 昨日完成 ...