Cod sursa(job #1358709)

Utilizator vergilius_beberindeie virgil vergilius_be Data 24 februarie 2015 19:19:24
Problema Progresie Scor 0
Compilator cpp Status done
Runda Arhiva ICPC Marime 0.9 kb
#include <iostream>
#include<stdio.h>
#include<cmath>
using namespace std;
FILE *f,*g;

int main()
{
    long long i,j,n,t,r,u,t1,k;
    double h;
    bool ok;
    f=fopen("progresie.in","r");
    g=fopen("progresie.out","w");
    fscanf(f,"%lld",&t);
    for(i=1;i<=t;i++)
    {
        fscanf(f,"%lld %lld",&n,&r);
        for(k=1;k<=1000000;k++)
        {
        for(j=k*(k-1)+1;j<=k*k;j++)
        {
                t1=j;
                ok=true;
                for(u=1;u<n;u++)
                {
                    t1=t1+r;
                    h=sqrt(t1);
                    if (h!=trunc(h))
                       if((t1<(trunc(h)+1)*trunc(h)+1 || t1>(trunc(h)+1)*(trunc(h)+1))) {ok=false; break;}
                }
                if(ok==true) break;
        }
      if(ok==true)  {fprintf(g,"%lld\n",j); break;}
    }
    }
    fclose(f);
    fclose(g);
    return 0;
}