首页 > 其他分享 >RSA(质因数分解,数论)

RSA(质因数分解,数论)

时间:2022-10-25 22:44:05浏览次数:62  
标签:输出 因数分解 数论 RSA credit int

RSA(质因数分解,数论)

题意

​ 给定两个正整数A, B,大小为1e12。如果他们是不同的质数,那么输出”full credit“;否则,若A * B是一个大于1的整数的平方的倍数,输出“no credit";否则,输出"partial credit"。

思路

​ 这是一道很CF风格的题目,我们很简单的可以知道,对A和B分解质因数之后,若有一个数出现过两次及以上,那么他就是一个大于1的整数的平方的倍数。如果两个是质数,那么他们分解质因数之后一定只有2个因子。其他情况就输出partial credit

代码

int a, b;
map<int, int> mp;

void divide(int x)
{
    for(int i = 2; i <= x / i; i ++)
    {
        int cnt = 0;
        if(x % i == 0)
            x /= i, cnt ++;
        if(cnt)
            mp[i] += cnt;
    }
    if(x > 1)
        mp[x] ++;
}

void solve()
{
    cin >> a >> b;
    if(a == b)
    {
        cout << "no credit\n";
        return;
    }
    divide(a); divide(b);

    int flag = 0;
    int cnt = 0;
    for(auto &[u, v] : mp)
    {
        cnt += v;
        if(v >= 2) //if(v >= 2)    x * x
        {
            flag = 1;
            break;
        }
    }


    if(!flag && cnt == 2) 
        cout << "full credit\n";
    else if(flag)  
        cout << "no credit\n";
    else
        cout << "partial credit\n";
}   

标签:输出,因数分解,数论,RSA,credit,int
From: https://www.cnblogs.com/DM11/p/16826674.html

相关文章