Pagini recente » Cod sursa (job #614549) | Cod sursa (job #2241766) | Cod sursa (job #2644620) | Cod sursa (job #566352) | Cod sursa (job #1709216)
#include <iostream>
#include <math.h>
#include <vector>
#include <stdio.h>
using namespace std;
FILE *g;
void afs(long n ){
// unsigned long cnt = 0;
vector<pair<long,long>> limite;
// long limite[100][2];
for(int i = 2; i <= 15; i++){
float mij = (float)n / i;
long first;
long last;
float rest = (mij - floor(mij));
if ( i % 2 == 0 && rest == 0.5){
first = ceil(mij - ((float)i/2));
last = floor(mij + ((float)i/2));
if(first > 0) {
// cout << first << " " << last << endl;
limite.push_back(make_pair(first,last));
// limite[cnt][0] = first;
// limite[cnt][1] = last;
// cnt ++;
} else{
break;
}
} else if(i % 2 != 0 && rest == 0.0){
first = mij - (i/2);
last = mij + (i/2);
if(first > 0){
// cout << first << " " << last << endl;
// limite[cnt][0] = first;
// limite[cnt][1] = last;
//
limite.push_back(make_pair(first,last));
// cnt ++;
} else{
break;
}
}
}
fprintf(g,"%d\n",limite.size());
// cout << cnt << endl;
for( auto &a : limite){
fprintf(g,"%d %d\n",a.first, a.second);
}
// if(cnt!=0)
// {
// for(int i = 0; i < cnt; i++){
// fprintf(g,"%d %d\n",limite[i][0], limite[i][1]);
//// cout << limite[i][0] << " " << limite[i][1] << endl;
// }
// }
}
int main()
{
FILE *f = fopen("consecutive.in","r");
g = fopen("consecutive.out","w");
int nrT;
long n ;
fscanf(f,"%d",&nrT);
for(int i = 0; i < nrT; i++){
fscanf(f, "%lu", &n);
afs(n);
}
return 0;
}