Another Problem About Dividing Numbers(数论分解质因子)

传送门

D. Another Problem About Dividing Numbers

You are given two integers a and b. In one turn, you can do one of the following operations:

  • Take an integer c (c>1 and aa should be divisible by c) and replace a with a/c;
  • Take an integer c (c>1 and b should be divisible by c) and replace b with b/c.

Your goal is to make a equal to b using exactly k turns.

For example, the numbers a=36 and b=48 can be made equal in 4 moves:

  • c=6, divide b by c ⇒⇒ a=36, b=8;
  • c=2, divide a by c ⇒⇒ a=18, b=8;
  • c=9, divide a by c ⇒⇒ a=2, b=8;
  • c=4, divide b by c ⇒⇒ a=2, b=2.

For the given numbers a and b, determine whether it is possible to make them equal using exactly k turns.

Input

The first line contains one integer t (1≤t≤1e4). Then t test cases follow.

Each test case is contains three integers a, b and k(1≤a,b,k≤1e9).

Output

For each test case output:

  • "Yes", if it is possible to make the numbers a and b equal in exactly k turns;
  • "No" otherwise.

The strings "Yes" and "No" can be output in any case.

 

 

8
36 48 2
36 48 3
36 48 4
2 8 1
2 8 2
1000000000 1000000000 1000000000
1 2 1
2 2 1
output
Copy
YES
YES
YES
YES
YES
NO
YES
NO

这个题目的意思就是说给你a,b,k;
你需要进行k轮游戏,每轮游戏你都可以选择一个a或者b进行操作,然后选择一个c(c不能为1),这个c必须是你之前选择的数的因子,
然后把你之前选择的是a或者b变成a/c或者b/c
问你进行完这k轮游戏,能不能使得a==b
首先我们考虑一种特殊情况就是当k==1的时候如果不是a%b=0或者是b%a==0,那么就输出'NO'
然后就是一般情况,我们发现我们是可以把a和b无论通过多少次变化都可以变成1的,因为a=p1^a1*p2^a2----*pn^an,然后就是
无论通过多少次变化都可以变成1的,然后设
a=p1^a1*p2^a2----*pn^an,b=b1^c1*b2^c2----bn^cn。然后就是suma=a1+a2+---an,sumb=c1+c2+---cn,
就是a和b最多改变suma+sumb次,就是说如果k<=suma+sumb的话就输出'yes',否者输出'no',
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=4e5+100;
int prime[maxn];
int biaoji[maxn];
int cnt;
void getPrime(){
    for(int i=2;i<maxn;i++){
        if(!biaoji[i]){
            prime[++cnt]=i;
        }
        for(int j=1;j<=cnt&&i*prime[j]<maxn;j++){
            biaoji[i*prime[j]]=1;
            if(i%prime[j]==0){
                break;
            }
        }
    }
}
typedef long long ll;//分解 
int dive(ll x){
    int sum=0;//6 
    for(int i=1;prime[i]*prime[i]<=x;i++){
        int z=0;
        while(x%prime[i]==0){
            x/=prime[i];
            z++;
        }
        sum+=z;
    }
    if(x!=1){
        sum++;//sum=sum(1*2+1);
    }
    return sum;
}
int main(){
    getPrime();
    int t;
    cin>>t;
    while(t--){
        ll a,b,k;
        cin>>a>>b>>k;
        if(a>b){
            swap(a,b);
        }
        if(k==1){
            if(b%a!=0||a==b){
                cout<<"NO"<<endl;
            }
            else{
                cout<<"YES"<<endl;
            }
            continue;
        }
        if(dive(a)+dive(b)>=k){
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }
    }
}

 

 


posted @ 2021-06-13 00:46  lipu123  阅读(218)  评论(0)    收藏  举报