-
Notifications
You must be signed in to change notification settings - Fork 12
/
10920.cpp
46 lines (29 loc) · 917 Bytes
/
10920.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <map>
using namespace std;
pair<int,int> solve(int P, int K){
long long aux = (long long)K * K;
int K2 = K / 2;
if(P > aux - K) return make_pair(P - aux + K2,K2);
aux -= K - 1;
if(P > aux - K) return make_pair(-K2,P - aux + K2);
aux -= K - 1;
if(P > aux - K) return make_pair(aux - P - K2,-K2);
aux -= K - 1;
return make_pair(K2,aux - P - K2);
}
int main(){
int N;
long long P;
while(true){
scanf("%d %lld",&N,&P);
if(N == 0) break;
int K = N;
while(K > 1 && (long long)(K - 2) * (K - 2) >= P) K -= 2;
pair<int,int> ret = solve(P,K);
ret.first = N / 2 + 1 + ret.first;
ret.second = N / 2 + 1 + ret.second;
printf("Line = %d, column = %d.\n",ret.first,ret.second);
}
return 0;
}