Cod sursa(job #1709079)

Utilizator ubb_oprimabuzurile_2016UBB - OprimAbuzurile2016 - Petru Bianca Cosmin ubb_oprimabuzurile_2016 Data 28 mai 2016 10:49:33
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.84 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#define LL long long
using namespace std;

bool cmp(pair<LL,LL> a,pair<LL,LL> b) {
  return a.second-a.first<b.second-b.first;
}

int main() {
  //ifstream f("input.txt");
  ifstream f("consecutive.in");
  ofstream g("consecutive.out");
  int t;

  for(f>>t;t--;) {
    LL n;
    vector<pair<LL,LL> > r;
    f>>n;
    for(LL i=1; i*i<=2*n; ++i) if((2*n)%i==0){
      LL d=i,nd=2*n/i;
      if((nd + d) % 2 == 0)
        continue;
      LL m=(nd+d-1)/2; LL p=m-d;
      if(m > 0 && p >= 0 && m != p+1)
        r.push_back(make_pair(p+1,m));
      swap(d,nd);
      m=(nd+d-1)/2; p=m-d;
      if(m > 0 && p >= 0 && m != p+1)
        r.push_back(make_pair(p+1,m));
    }
    sort(r.begin(),r.end(),cmp);
    g<<r.size()<<'\n';
    for(auto i:r) g<<i.first<<' '<<i.second<<'\n';
  }
}