sgu 443. Everlasting...? 素数筛

本文介绍了一款名为Everlasting Sa-Ga的游戏中的迷宫谜题解决方法,通过计算每个门对应的整数的关键数值来确定通往宝藏室的正确路径。文章详细解释了关键数值的计算方法,并提供了一个算法实现示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

443. Everlasting...?
Time limit per test: 0.5 second(s)
Memory limit: 262144 kilobytes
input: standard
output: standard

Everlasting Sa-Ga, a new, hot and very popular role-playing game, is out on October 19, 2008. Fans have been looking forward to a new title of Everlasting Sa-Ga. Little Jimmy is in trouble. He is a seven-year-old boy, and he obtained the Everlasting Sa-Ga and is attempting to reach the end of the game before his friends. However, he is facing difficulty solving the riddle of the first maze in this game — Everlasting Sa-Ga is notorious in extremely hard riddles like Neverending Fantasy and Forever Quest. The riddle is as follows. There are two doors on the last floor of the maze: the door to the treasure repository and the gate to the hell. If he wrongly opens the door to the hell, the game is over and his save data will be deleted. Therefore, he should never open the wrong door. So now, how can he find the door to the next stage? There is a positive integer given for each door — it is a great hint to this riddle. The door to the treasure repository has the integer that gives the larger key number. The key number of a positive integer n is the largest prime factor minus the total sum of any other prime factors, where the prime factors are the prime numbers that divide into n without leaving a remainder. Note that each prime factor should be counted only once. As an example, suppose there are doors with integers 30 and 20 respectively. Since 30 has three prime factors 2, 3 and 5, its key number is 5 - (2 + 3) = 0. Similarly, since 20 has two prime factors 2 and 5, its key number 20 is 5 - 2 = 3. Jimmy therefore should open the door with 20. Your job is to write a program to help Jimmy by solving this riddle. 
Input
The input consists of a line that contains two integers a and b separated by a space (2 ≤ ab ≤ 106). It is guaranteed that key numbers of these integers are always different. 
Output
Print in a line '
a
' (without quotes) if the door with the integer a is connected to the treasure repository; print '
b
' otherwise. 
Example(s)
sample input
sample output
10 15
a

sample input
sample output
30 20
b


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

bool v[1000005];
queue<int> q;
int main(){
    for(int i=2;i*i<=1000000;i++){
        if(v[i]==1)continue;
        for(int j=2*i;j<=1000000;j+=i){
            v[j]=1;
        }
    }
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i=a;i>=2;i--){
        if(v[i])continue;
        if(a%i==0)q.push(i);
    }
    int ans1=q.front();
    q.pop();
    while(!q.empty()){
        ans1-=q.front();
        q.pop();
    }
    for(int i=b;i>=2;i--){
        if(v[i])continue;
        if(b%i==0)q.push(i);
    }
    int ans2=q.front();
    q.pop();
    while(!q.empty()){
        ans2-=q.front();
        q.pop();
    }
//    cout<<ans1<<endl;
//    cout<<ans2<<endl;
    printf("%c",ans1>ans2?'a':'b');
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值