点此看题面

大致题意:\((n-1)!\ mod\ n\)的值。

大力猜结论

首先,看到样例,我们可以猜测:

  • \(n\)为质数时,答案为\(n-1\)
  • \(n\)为合数时,答案为\(0\)

这样一交,你就会发现你WA了。

那么上面的结论错在哪里呢?

其实只要特判\(n=4\)时输出\(2\)即可。

证明?我不会。

代码

#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
using namespace std;
int n;
I bool IsPrime(CI x)//判断是否为质数
{
	RI i;for(i=2;1LL*i*i<=x;++i) if(!(x%i)) return false;
	return true;
}
int main()
{
	return scanf("%d",&n),printf("%d",n==4?2:(IsPrime(n)?n-1:0)),0;//输出答案
}

相关文章:

  • 2022-02-07
  • 2021-06-08
  • 2021-11-09
  • 2022-02-15
  • 2022-12-23
  • 2021-11-22
  • 2022-02-01
  • 2021-11-01
猜你喜欢
  • 2021-06-04
  • 2021-05-24
  • 2021-11-30
  • 2021-12-12
  • 2021-09-01
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案