21 November 2015

Lightoj 1008- Fibsieve`s Fantabulous Birthday

This problem is quite easy. Look carefully that if we square root s and take it ceil n, then the abscissa or the ordinate will be equal to n. After that find k = m -n +1 which will help to determine that intersection number as like 1,3,7,13,21. When you will know the k ,check whether s is greater than or  less then from k . if( s>k) x =n and  y = m -s +1 and if(s<k) then y =n  and x = s-a+1 where a is smallest number for that color.
The above process is when m is odd. If m is even the process is just reverse for x & y.
Beware about range of s


/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size)  for(int i=0 ; i<size ; i++) cin>>array[i]  ;
#define new_line  pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647

int main()
{
    int test ;
    ll cnt =1 ;
    sc("%d",&test) ;

    while(test--)
    {
        ll s ;
       cin>>s ;
        ll n = ceil(sqrt(s)) ;
        ll m = n*n ;
        ll x ,y ;
        if(m&1)
        {
            ll k = m -n +1 ;
            if(k==s)
                x=y=n ;

            else if(s>k){
                x = n ;
                y = m -s +1 ;
            }

            else if(s<k){
                y =n ;
                ll a  = m - (2*n)+2 ;
                x = s- a +1 ;
            }

            cout<<"Case "<<cnt++<<": "<<y<<" "<<x<<endl ;        }
        else
        {
         ll k = m -n +1 ;
            if(k==s)
                x=y=n ;

                else if(s<k){
                    x =n ;
                    ll a = m - (2*n)+ 2 ;
                    y = s-a+1 ;
                }

                else if(s>k){
                    y =n ;
                    x =m-s+1 ;
                }
               cout<<"Case "<<cnt++<<": "<<y<<" "<<x<<endl ;
        }
    }
    return 0;
}

1 comment:

  1. a = m - (2*n)+ 2 ; Could you please explain where did you get this formula.

    ReplyDelete

UVA 10679 - I Love Strings!!