Last active
April 6, 2017 05:07
-
-
Save Cycatz/5ea7530e94427efbd837bc7c10d12a13 to your computer and use it in GitHub Desktop.
[Uva]10161 - Ant on a Chessboard
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| #include<cmath> | |
| #include<cstdio> | |
| using namespace std ; | |
| void r(long long sum , long long k , long long &in1 , long long &in2) | |
| { | |
| if(sum <= k) | |
| in1++ , in2 += sum ; | |
| else if(sum > k) | |
| in1 -= sum - (k + 1) , in2 += k ; | |
| } | |
| int main() | |
| { | |
| long long n ; | |
| while(cin >> n && n) | |
| { | |
| long long k = sqrt(n) , kk = k * k; | |
| long long in1 , in2 , sum = 0 ; | |
| if(kk % 2) in1 = k , in2 = 1 ; | |
| else in1 = 1 , in2 = k ; | |
| if(n - kk == 0) | |
| printf("%lld %lld\n" , in2 , in1); | |
| else | |
| { | |
| long long sum = n - kk - 1; // step long | |
| if(kk % 2) r(sum , k , in1 , in2); | |
| else r(sum , k , in2 , in1); | |
| printf("%lld %lld\n" , in2 , in1); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment