补一下题 之前比赛的时候没有写出来
题目链接:登录—专业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;
}
1943

被折叠的 条评论
为什么被折叠?



