-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva10920.cpp
More file actions
50 lines (46 loc) · 1.32 KB
/
Copy pathUva10920.cpp
File metadata and controls
50 lines (46 loc) · 1.32 KB
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
47
48
49
50
#include <iostream>
#include <math.h>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <algorithm>
#include <map>
#include <sstream>
using namespace std;
long long SZ, P;
int main() {
for(;;) {
scanf("%lld %lld", &SZ, &P);
if(SZ == 0 && P == 0) break;
// get next highest anchor
long long root = sqrt(P);
if(root * root == P && root % 2 == 1) {
} else if(root % 2 == 1) root += 2;
else root++;
long long i = root / 2, j = root / 2;
if(root * root != 1) {
long group = (root * root - P) / (root - 1);
switch(group) {
case 0:
i -= root * root - P;
break;
case 1:
i -= root - 1;
j -= (root * root - P - (root - 1));
break;
case 2:
i -= (root - 1) - (root * root - P - (root - 1) * 2);
j -= root - 1;
break;
case 3:
j -= (root - 1) - (root * root - P - (root - 1) * 3);
break;
}
}
printf("Line = %lld, column = %lld.\n", i + SZ / 2 + 1, j + SZ / 2 + 1);
}
}