HDU 5019 Revenge Of gcd (Mathematics)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.