#include <iostream>
using namespace std;

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
int main() {
    int C,R;
    cin >> C >> R;
    long long k;
    cin >> k;
    if (k>R*C) {
        cout << 0;
        return 0;
    }
    int arr[1001][1001] = {0,};
    int b = 0;
    int x = 1;
    int y = 1;
    int nx = 1;
    int ny = 1;
    arr[0][0] = 1;
    for (int i = 1;i <= k ;i++) {
        if(i==k)
        {
            cout << x << " " << y;
            return 0;
        }
        
        arr[x][y] = 1;
        nx = x+dx[b];
        ny = y+dy[b];
    //   cout << x << " " << y << " " << i << " " << b << "\n";
        if (arr[x+dx[b]][y+dy[b]] == 1 ||1 > y+dy[b] || y+dy[b] > R ||1 > x+dx[b] || x+dx[b] > C) {
            b = (b+1)%4;
            nx = x+dx[b];
        ny = y+dy[b];
            
        }
            //cout << x << " " << y << " " << nx << " " << ny << " "<< i << " " << b << "\n";
        
        x = nx;
        y = ny;
    }

    cout << x << " " << y;
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: