Pagini recente » Cod sursa (job #545299) | infoarena - comunitate informatica, concursuri de programare | Cod sursa (job #1493515) | Cod sursa (job #1149013) | Cod sursa (job #1349667)
#define _CRT_SECURE_NO_WARNINGS
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define IN_FILE_NAME "progresie.in"
#define OUT_FILE_NAME "progresie.out"
unsigned int CheckNr(unsigned int nr)
{
unsigned int sqrtInt = (unsigned int)(sqrt(1.0 * nr));
double sqrtDouble = sqrt(1.0 * nr);
if(sqrtDouble == sqrtInt) return 0;
if(nr > sqrtInt * (sqrtInt + 1) && nr < (sqrtInt + 1) * (sqrtInt + 1))
return 0;
return sqrtInt * (sqrtInt + 1) + 1 - nr;
}
int main()
{
freopen(IN_FILE_NAME, "r", stdin);
freopen(OUT_FILE_NAME, "w", stdout);
unsigned int tests = 0, t;
scanf("%d", &tests);
for(t=0; t<tests; t++)
{
unsigned int globalMove = 0;
bool found = false;
unsigned int maxMove = 0;
unsigned int n=0, r=0;
scanf("%d %d", &n, &r);
unsigned int i,j;
for(i=1; i<=(n-1)*r; i++)
{
maxMove = 0;
unsigned int start = 1+i*(i-1)+globalMove;
unsigned int stop = i*i;
for(j=start; j<=stop; j++)
{
unsigned int k;
found = true;
for(k=1; k<n; k++)
{
unsigned int nr = j+k*r;
unsigned int sqrtInt = (unsigned int)(sqrt(1.0 * nr));
double sqrtDouble = sqrt(1.0 * nr);
if(sqrtDouble == sqrtInt) return 0;
if(nr > sqrtInt * (sqrtInt + 1) && nr < (sqrtInt + 1) * (sqrtInt + 1))
return 0;
unsigned int localMove = sqrtInt * (sqrtInt + 1) + 1 - nr;
if(localMove != 0) {found=false; break;}
}
if(found) {
printf("%u\n", j);
break;
}
}
if(found) break;
//prunsigned intf("\n");
}
if(!found)
{
printf("%u\n", 1 + ((n-1)*r+1) * ((n-1)*r));
}
}
return 0;
}