lightOJ 1008 - Fibsieve`s Fantabulous Birthday

看成正方形,每个就是1,2,3,4,5...的平方围成的图形,然后就可以找到规律了

#include <iostream>
#include <cstdio>
#include <cmath>
 
using namespace std;
 
int main()
{
    int T,cas=0;
    cin >> T;
    while(T--)
    {
        long long num;
        cin >> num;
        double tmp = sqrt(double(num));
        tmp = tmp==(int)tmp?tmp:tmp+1;
        long long pos=(long long)tmp;
        printf("Case %d: ",++cas);
        if(pos&1)
        {
            if(num > pos*pos-pos)
                printf("%lld %lld\n",pos*pos-num+1,pos);
            else
                printf("%lld %lld\n",pos,num-(pos-1)*(pos-1));
        }
        else
        {
            if(num > pos*pos-pos)
                printf("%lld %lld\n",pos,pos-(num-(pos*pos-pos+1)));
            else
                printf("%lld %lld\n",num-(pos-1)*(pos-1),pos);
        }
    }
    return 0;
}


</pre><pre>

你可能感兴趣的:(数学思维,lightoj)