light oj 1008

一个规律题 一开始还傻*的二分。。。诶。。。不过值得注意的是,sqrt的返回值,10e15不小心是会变成负的。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
ll ans;
int T,cas=1,x,y;
int main()
{
//    for (long long i=1; i<MAXN; i++) a[i]=i*i;
    scanf ("%d",&T);
    while (T--)
    {
        ll n;
        scanf ("%lld",&n);
        if ((ll)sqrt(n*1.0)*sqrt(n*1.0)==n)
        {
            if (n%2==0)
            {
                printf ("Case %d: ",cas++);
                printf ("%.0f %d\n",sqrt(n*1.0),1);
            }
            else
            {
                printf ("Case %d: ",cas++);
                printf ("%d %.0f\n",1,sqrt(n*1.0));
            }
        }
        else
        {
            int pos=(int)sqrt(n);
//            int pos=lower_bound(a,a+32000000,n)-a;
//            printf ("pos=%d,a[pos]=%lld\n",pos,a[pos]);
            if (pos%2==0)
            {
                x=pos+1;
                y=1;
                long long temp=n-(long long)pos*pos-1;
                if (temp<=pos) y+=temp;
                else {y+=pos;x-=(temp-pos);}
            }
            else
            {
                x=1;
                y=pos+1;
                long long temp=n-(long long)pos*pos-1;
                if (temp<=pos) x+=temp;
                else {x+=pos;y-=(temp-pos);}
            }
            printf ("Case %d: %d %d\n",cas++,x,y);
        }
    }
    return 0;
}

 



转载于:https://www.cnblogs.com/nj-czy/p/5287999.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值