UVa 10161

我是用笨方法做的,首先找出该值的范围,然后分奇数偶数讨论。

#include "stdio.h"
#include "math.h"

int main()
{
 int n;
 int temp;

 while(scanf("%d",&n)==1&&n)
 {
  temp=(int)pow(n,0.5);

  if(temp*temp==n)
  {
   if(temp%2==0)
    printf("%d 1\n",temp);
   else
    printf("1 %d\n",temp);
   continue;
  }

  if(temp%2==0)
  {
   if(n-temp*temp<=temp+1)
    printf("%d %d\n",temp+1,n-temp*temp);
   else
    printf("%d %d\n",(temp+1)*(temp+1)-n+1,temp+1);
  }
  else
  {
   if(n-temp*temp<=temp+1)
    printf("%d %d\n",n-temp*temp,temp+1);
   else
    printf("%d %d\n",temp+1,(temp+1)*(temp+1)-n+1);
  }

 }

 return 0;
}

只要是知道排数的规则,用这个方法再加上细心一点就可以搞定了……

原文地址:https://www.cnblogs.com/Shirlies/p/2325959.html