CERC2017 F: Faulty Factorial 简单数论题
2024-09-04 10:23:34
#include <iostream>
using namespace std;
#define ll long long
const int N = ;
ll n,p,r;
ll poww(ll a,ll b){
ll ans =1ll;
while(b){
if(b&) ans =ans*a%p;
b>>=;
a=a*a%p;
}
return ans%p;
}
int main()
{
//每次都要注意-1 -1的情况
scanf("%lld%lld%lld",&n,&p,&r);
if(n>=*p){
if(r==){
printf("%lld 1\n",p+);
}
else{
printf("-1 -1\n");
}
}
else if(n>=p){
if(r==){
int flag =;
for(ll i=;i<=n;i++){
if(i!=p)//起初if的{}写错了
{
printf("%lld 1\n",i);
flag =;
break;
}
}
if(!flag)printf("-1 -1\n"); //n=p=2
}
else{
ll ans=1ll;
for(ll i=;i<=n;i++) {
if(i!=p) ans =ans*i%p;
}
int flag =;
for(ll i=;i<p;i++){
if(ans*i%p==r) {
printf("%lld %lld\n",p,i);
flag =;
break;
}
}
if(flag==) printf("-1 -1\n");
}
}
else{
ll ans =1ll;
for(ll i=;i<=n;i++) ans =ans*i%p;
int flag =;
ans = poww(ans,p-);//放到里面会超时
for(ll i=;i<=n;i++){
ll x= r*i%p*ans%p;
// ans/i*x%p==r
// x=r*i%p/ans%p;
if(x>=&&x<i){
printf("%lld %lld\n",i,x);
flag =;
break;
}
}
if(!flag) printf("-1 -1\n");
}
return ; }
最新文章
- php安装的一点点事 ---wampserver
- 标识符,unicode和GBK
- Npoi实现Excel绘制功能
- 详解CSS中clear属性both、left、right值的含义
- Mysql denied for user &#39;odbc@localhost&#39; || denied for user &#39;root@localhost&#39;
- 支持Ajax跨域访问ASP.NET Web Api 2(Cors)的简单示例教程演示
- select()函数以及FD_ZERO、FD_SET、FD_CLR、FD_ISSET(转)
- xml装php数组
- SPI Flash
- CentOS的ssh sftp配置及权限设置(流程相当完整)(关闭了SElinux才能上传了)
- SQlServer---时间的操作
- file_get_contents和curl对于post方式的解决办法
- ActiveMQ笔记——技术点汇总
- php中各种定义变量的方法
- Excel 2010高级应用-条状图(五)
- SVN系列操作(二)&;svn不显示图标的解决方法
- css3 实现波浪(wave)效果
- 机器学习实战1-1 KNN电影分类遇到的问题
- 简单的图像显著性区域特征提取方法-----opencv实现LC,AC,FT
- select as table
热门文章
- 谷歌浏览器web worker出现cannot be accessed from origin &#39;null&#39;错误
- 《ArcGIS Runtime SDK for Android开发笔记》——(2)、Android Studio基本配置与使用
- SQLServer 连接和联合
- 复制windows CMD命令行中的内容
- Docker build 安装报错, Could not open requirments file: [Errno 2] No such file or directory:&#39;requirements.txt&#39;
- Arduino-定义串口
- Jmeter入门7 测试中使用到的几个定时器和逻辑控制器
- Illegal access:this web application instance has been stopped already
- node.js 练习2 (调用函数)
- 编写第一个OpenACC程序