广工21级新生赛A题

补一下题 之前比赛的时候没有写出来

题目链接:登录—专业IT笔试面试备考平台_牛客网

思路

        思路1 发现模数是一个特殊的数 103!可以把模数整除 所以当n>=103 的时候 n!%mod == 0

        思路2 你没有发现这个规律 但是由于做题经验告诉你 这种题目会在n达到某一个特定条件的时候为0 不然设置余数的意义就不存在了

代码

思路1的代码实现

#include <iostream>
 
using namespace std;
#define mod 999068070;
typedef long long LL;
 
LL jc(int n)
{
    if(n >= 103)    return 0;
    LL ans = 1;
    for(int i = 2; i <= n; i++)
        ans = ans * i % mod;
    return ans;
}
int main()
{
    int a, b;
    cin >> a >> b;
    if(jc(a) > jc(b))    cout << "a is the winner!" << endl;
    else if(jc(a) < jc(b))    cout << "b is the winner!" << endl;
    else cout << "There is no winner!" << endl;
    return 0;
}

思路2的代码实现

#include <iostream>

using namespace std;
typedef long long LL;
#define mod 999068070;
int main()
{
    LL a,b;
    cin>>a>>b;
    LL resA=1,resB=1;
    
    for(int i=1;i<=a;i++)
    {
        resA=resA*i%mod;
        if(resA==0) break;
    }
    for(int i=1;i<=b;i++)
    {
        resB=resB*i%mod;
        if(resB==0) break;
    }
    
    if(resA>resB) cout<<"a is the winner!"<< endl;
    else if (resA<resB) cout<<"b is the winner!"<< endl;
    else cout<<"There is no winner!"<< endl;
   	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值