Skip to content

Instantly share code, notes, and snippets.

@tabvn
Last active October 18, 2018 05:43
Show Gist options
  • Select an option

  • Save tabvn/18f0c84acc113ee0921d056d0dd9f7f7 to your computer and use it in GitHub Desktop.

Select an option

Save tabvn/18f0c84acc113ee0921d056d0dd9f7f7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fi ("CANARIUM.INP");
ofstream fo ("CANARIUM.OUT");
vector<long long> v;
int main(){
int t;
long long n;
float m;
long long k; // so k
fi >> t;
for (int i = 0; i < t; ++i){
fi >> k;
v.push_back(k);
}
/*
goi n la là số hình chư nhật đếm theo hàng ngang
m là số hình chữ nhật đếm theo hàng dọc
[[2(n-1) + 1] * (m-1)] + n = tram*2;
=> (2n-1)*(m-1) + n = tram*2
dieu kien la n >= m >= 1
=> m = (tram*2 + n -1)/(2n-1)
*/
for (int i = 0; i < v.size(); ++i){
k = v[i];
n = 1;
m = k;
while(n<k*2){
m = float(k*2 + n -1)/(2*n -1);
if(n >= m && (int)m == m ){
break;
}
n++;
}
if(m < n && (int)m == m){
// chi tinh sô đường hàng ngang or dọc , ko tính ô chữ nhật nên ta -1
fo << m -1 << " " << n -1 << endl;
}else{
fo << -1 << -1 << endl;
}
}
fi.close();
fo.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment