Cod sursa(job #1708957)
Utilizator | Udristoiu Alexandra Maria alexandra_udristoiu | Data | 28 mai 2016 10:22:23 |
---|---|---|---|
Problema | Consecutive | Scor | 0 |
Compilator | cpp | Status | done |
Runda | ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest | Marime | 0.72 kb |
#include<fstream>
using namespace std;
int t, n, i, x, nr;
pair<int, int> sol[30000];
ifstream fin("consecutive.in");
ofstream fout("consecutive.out");
int main(){
fin>> t;
for(; t; t--){
fin>> n;
nr = 0;
for(i = 2; i <= n; i++){
x = i * 1LL * (i + 1) / 2;
if(x > n){
break;
}
x = n - i * (i - 1) / 2;
if(x % i == 0){
nr++;
sol[nr].first = x / i;
sol[nr].second = sol[nr].first + i - 1;
}
}
fout<< nr <<"\n";
for(i = 1; i <= nr; i++){
fout<< sol[i].first <<" "<< sol[i].second <<"\n";
}
}
}