LightOJ---1008

  1.   
    Time Limit:500MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu 
    /********************************************** 
     
         author   :   *******
         time     :   *******
         algorithm:   数论 
         explain  :    对n开平方然后向上取整得到m: 
                          如果m为奇数: 
                                if(m*m-n<m)    y=m;x=m*m-n+1; 
                                   else  x=m;y=n-(m-1)*(m-1); 
     
                          如果m为偶数: 
                                 if(m*m-n<m)    x=m;y=m*m-n+1; 
                                    else   y=m;x=n-(m-1)*(m-1); 
     
    **********************************************/  
    
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <stack>
    #include <map>
    #include <vector>
    using namespace std;
    
    const int maxn=210;
    const int INF=0x3f3f3f3f;
    
    long long t,n,x,y;
    long long z;
    long long m;
    
    int main()
    {
        scanf("%d",&t);
        for(int i=1; i<=t; i++)
        {
            scanf("%lld",&n);
            z=sqrt(n*1.0);
    
            if(z*z==n) m=z;
            else m=z+1;
    
            if(m%2)
            {
                if(m*m-n<m)
                {
                    y=m;
                    x=m*m-n+1;
                }
                else
                {
                    x=m;
                    y=n-(m-1)*(m-1);
                }
            }
            else
            {
                if(m*m-n<m)
                {
                    x=m;
                    y=m*m-n+1;
                }
                else
                {
                    y=m;
                    x=n-(m-1)*(m-1);
                }
            }
            printf("Case %d: %lld %lld
    ",i,x,y);
        }
        return 0;
    }
原文地址:https://www.cnblogs.com/w-y-1/p/5755446.html