/ /

记录详情

Accepted

foo.cc: In function 'int main()':
foo.cc:21:7: warning: unused variable 'j' [-Wunused-variable]
 ll i, j, n, m;
       ^
foo.cc:21:13: warning: unused variable 'm' [-Wunused-variable]
 ll i, j, n, m;
             ^
foo.cc:22:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%lld", &n);
 ~~~~~^~~~~~~~~~~~
foo.cc:24:6: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 scanf("%lld %lld", &p[i], &a[i]);
 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
正在同步测试数据,请稍后
[Hydro](https://hydro.ac)提供评测服务
# 状态 耗时 内存占用
#1 Accepted 2ms 352.0 KiB
#2 Accepted 2ms 384.0 KiB
#3 Accepted 2ms 384.0 KiB
#4 Accepted 2ms 384.0 KiB
#5 Accepted 2ms 384.0 KiB
#6 Accepted 2ms 384.0 KiB
#7 Accepted 2ms 384.0 KiB
#8 Accepted 2ms 384.0 KiB
#9 Accepted 2ms 384.0 KiB
#10 Accepted 2ms 384.0 KiB

代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
ll M = 1, p[105], a[105], ans;
void exgcd(ll a, ll b, ll &x, ll &y){
if(b == 0) x = 1, y = 0;
else {
exgcd(b,a%b,y,x);
y -= (a/b) * x;
}
}
ll inv(ll a, ll b){
ll x, y;
exgcd(a,b,x,y);
return (x%b+b)%b;
}
int main(){
ll i, j, n, m;
scanf("%lld", &n);
for(i = 1; i <= n; i++){
scanf("%lld %lld", &p[i], &a[i]);
M *= p[i];
}
for(i = 1; i <= n; i++) p[i] = M / p[i];
for(i = 1; i <= n; i++){
ans += inv(p[i], M/p[i]) * a[i] * p[i] % M;
}
ans %= M;
printf("%lld",ans);
return 0;
}

信息

递交者
类型
递交
题目
P1071 曹冲养猪
题目数据
下载
语言
C++
递交时间
2021-08-18 09:23:17
评测时间
2021-08-18 09:23:17
评测机
分数
100
总耗时
23ms
峰值内存
384.0 KiB