Number of K conventions (simple mathematics, logic conversion)

Source: Internet
Author: User
Tags gcd greatest common divisor

Encountered a very interesting topic, requiring two numbers of the number of K conventions (of course k=1 is greatest common divisor), such as

12 6 2

3

Range, A and b<=1e14,k<=1e9.

So violence is certainly not, the crux of the problem is: can be greatest common divisor divisible by the number of two number of conventions!! That's what you can do.

1#include <iostream>2#include <string>3#include <algorithm>4#include <vector>5#include <cstdio>6#include <cstring>7#include <cmath>8 using namespacestd;9typedefLong Longll;Ten ll A,b,k; One ll gcd (ll A,ll b) A { -     returnB?GCD (b,a%b): A; - } the BOOLcmp (ll aa,ll BB) - { -     returnAa>BB; - } +Vector<ll>Vec; -  + intMain () A { atIos::sync_with_stdio (false); Cin.tie (0); -  -Cin>>a>>b>>K; -  -ll ans=gcd (A, b); -      for(LL i=1; i*i<=ans;i++)//greatest common divisor divisible is also the number of Conventions! in     { -         if(ans%i==0) to         { + Vec.push_back (i); -ll j=ans/i; the             if(j!=i) Vec.push_back (j); *         } $     }Panax Notoginseng  - sort (Vec.begin (), Vec.end (), CMP); the     if(K>vec.size ()) cout<<"No solution!"<<Endl; +     Elsecout<<vec[k-1]<<Endl; A  the     return 0; +}

Finish.

Number of K conventions (simple mathematics, logic conversion)

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.