Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 5019
Problem descriptionin mathematics, the greatest common divisor (GCD), also known as the greatest common factor (GCF), highest common factor (HCF), or greatest common measure (GCM ), of two or more integers (when at least one of them is not zero), is the largest positive integer that divides the numbers without a remainder.
--- Wikipedia
Today, gcd takes revenge on you. You have to figure out the k-th GCD of X and Y. inputthe first line contains a single integer T, indicating the number of test cases.
Each test case only contains three integers x, y and K.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= x, y, k <= 1 000 000 000
Outputfor each test case, output the k-th GCD of X and Y. If no such integer exists, output-1. sample input
32 3 12 3 28 16 3
Sample output
1-12
Sourcebestcoder round #10
Official question:
The Code is as follows:
# Include <cstdio> # include <cstring> # include <cmath> # include <iostream> # include <algorithm> # include <vector> using namespace STD; typedef _ int64 ll; vector <ll> V; ll gcd (ll a, LL B) {If (B = 0) return a; return gcd (B, A % B );} int main () {int t; ll X, Y, K; scanf ("% d", & T); While (t --) {v. clear (); scanf ("% i64d % i64d % i64d", & X, & Y, & K); ll tt = gcd (x, y ); // printf ("% i64d \ n", TT); For (ll I = 1; I * I <= tt; I ++) {if (Tt % I = 0) {v. push_back (I); if (I * I! = TT) // prevent two I v. push_back (TT/I);} Sort (v. begin (), V. end (); If (k> v. size () printf ("-1 \ n"); else printf ("% i64d \ n", V [v. size ()-K]);} return 0 ;}
HDU 5019 Revenge Of gcd (Mathematics)