মঙ্গলবার, ৩০ আগস্ট, ২০১৬

UVA 10161 - Ant on a Chessboard

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<ctype.h>
using namespace std;
main()
{
long long int n;
while(scanf("%lld",&n)!=EOF)
{
if(n==0)
break;
else
{
long long r,k,k1,diff=0,x=0,y=0;
r=ceil(sqrt(n));
diff=(r*r)-n;
k=(2*r)-1;
k1=k/2;
if(r%2==1)
{
if(diff>k1)
{
x=r;
y=k-diff;
}
else
{
y=r;
x=diff+1;
}
}
else
{
if(diff>k1)
{
y=r;
x=k-diff;
}
else
{
x=r;
y=diff+1;
}
}
printf("%lld %lld\n",x,y);
}
}
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন

Factory Pattern

Factory Method  is a creational design pattern that provides an interface for creating objects in a superclass but allows subclasses to alte...