LightOJ 1008 Fibsieve`s Fantabulous Birthday

题意:

看上面那个图,问你数字 \(n\) 的位置


先找出不超过 \(n\) 的最大完全平方数,然后按照奇偶性判断推一推柿子就行了

时间复杂度 \(O(1)\)

// This code Write By chtholly_micromaker(MicroMaker)
#include <cstdio>
#include <cctype>
#include <cmath>
#define reg register
#define int long long
using namespace std;
template <class t> inline void rd(t &s)
{
    s=0;
    reg char c=getchar();
    while(!isdigit(c))
        c=getchar();
    while(isdigit(c))
        s=(s<<3)+(s<<1)+(c^48),c=getchar();
    return;
}
inline void work()
{
    int n;rd(n);
    reg int p=sqrt(n);
//  printf("P %lld\n;",p);
    if(p*p==n)
    {
        if(p&1)
            printf("1 %lld\n",p);
        else
            printf("%lld 1\n",p);
        return;
    }
    if(p&1)
    {
        int lsts=p*(p+1)+1;
        if(n<lsts)
            printf("%lld %lld\n",p+1-lsts+n,p+1);
        else
            printf("%lld %lld\n",p+1,p+1-n+lsts);
    }
    else
    {
        int lsts=p*(p+1)+1;
        if(n>=lsts)
            printf("%lld %lld\n",p+1-n+lsts,p+1);
        else
            printf("%lld %lld\n",p+1,p+1-lsts+n);
    }
    return;
}
signed main(void)
{
    int t;rd(t);
    for(int i=1;i<=t;++i)
        printf("Case %lld: ",i),work();
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/chinesepikaync/p/12300207.html