Cod sursa(job #1709094)

Utilizator mihaipopa12Popa Mihai mihaipopa12 Data 28 mai 2016 10:52:35
Problema Consecutive Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.69 kb
#include <stdio.h>
#include <vector>

using namespace std;

int main() {
  freopen("consecutive.in", "r", stdin);
  freopen("consecutive.out", "w", stdout);

  int tests; scanf("%d", &tests);
  while (tests--) {
    long long x; scanf("%lld", &x);

    vector<pair<int, int>> sol;
    long long sum = 0;
    for (long long nr = 2; ; ++nr) {
      sum += nr - 1;
      long long y = x - sum;
      if (y > 0 && y % nr == 0) {
        long long start = y / nr;
        sol.push_back(make_pair(start, start + nr - 1));
      }
      if (y <= 0) {
        break;
      }
    }

    printf("%d\n", (int) sol.size());
    for (auto &p : sol) {
      printf("%d %d\n", p.first, p.second);
    }
  }

  return 0;
}