Obtain all the positive integer pairs so that their maximum approximate number is n, and the minimum public multiple is m.

Source: Internet
Author: User

Obtain all the positive integer pairs so that their maximum approximate number is n, and the minimum public multiple is m.

 

 

The general idea is to find all the positive integer pairs so that their maximum approximate number is n, and the minimum public factor is m. (1 <= n, m <= 10 ^ 10)

The problem can be converted to: Set a and B to the integer pair, where n, a, B, and m can all be divided by n, the question is converted to the logarithm of m/n, where the maximum public approx. Is 1 and the minimum public multiple is m/n.

That is, the logarithm of m/n multiplied by 1 to m/n. It can be solved in O (sqrt (m/n.

 

 

#include #include 
 
  #include 
  
   #include 
   
    #include 
    
     #include 
     
      #define MAX 0x3f3f3f3f#define N 2000005typedef long long LL;using namespace std;int T;LL n, m;LL gcd(LL a, LL b) {    return b == 0 ? a : gcd(b, a % b);}int main(){    cin>>T;while(T--) {        cin >> n >> m;        if(m % n) {            printf(0);            continue;        }        LL x = m / n;        int ans = 0;        for(LL i = 1; i <= (LL)sqrt(x); i++) {            if(x % i == 0) {                LL j = x / i;                if(gcd(i, j) == 1) ans++;            }        }        printf(%d, ans);    }    return 0;}
     
    
   
  
 

 

 

??

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.