#include <iostream>                                                                                                                               
#include <map>                                                                                                                                    
#include <vector>                                                                                                                                 
using namespace std;                                                                                                                              
                                                                                                                                                  
int main() {                                                                                                                                      
    int a, b, k;                                                                                                                                  
    cin >> a >> b >> k;                                                                                                                           
                                                                                                                                                  
    int n;                                                                                                                                        
    n = a < b ? a : b;                                                                                                                            
                                                                                                                                                  
    int cnt = 0;                                                                                                                                  
    for (int i = n; i >= 1; i--) {                                                                                                                
        if (!(a % i) && !(b % i)) {                                                                                                               
            cnt++;                                                                                                                                
            if(cnt == k) {                                                                                                                        
                cout << i << endl;                                                                                                                
                break;                                                                                                                            
            }                                                                                                                                     
        }                                                                                                                                         
    }                                                                                                                                             
}        

Measured memory_bytes: 256