QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#659103 | #5301. Modulo Ruins the Legend | SYease | WA | 0ms | 3628kb | C++17 | 1.6kb | 2024-10-19 18:39:32 | 2024-10-19 18:39:39 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<set>
#include<cmath>
#include<queue>
#define int long long
#define endl '\n'
#define F first
#define S second
#define sz size()
#define B begin()
#define D end()
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int N=1e6+10;
const int mod=1e9+7;
int ksm(int m,int k,int mod);
int gcd(int a,int b);
int exgcd(int a,int b,int &x,int &y);
int n,m;
int a[N];
void solve()
{
cin>>n>>m;
int sum=0;
for(int i=1;i<=n;i++){
int a;
cin>>a;
sum+=a;
}
int k=gcd(n,n*(n+1)/2);
int g=gcd(k,m);
int p=(-sum)/g;
int ans_f=p*g;
int ans=ans_f+sum;
int x,y;
int s,d;
exgcd(k,m,x,y);
x=x*p;
y=y*p;
exgcd(n,(n+1)*n/2,s,d);
s*=(ans_f-m*y);
d*=(ans_f-m*y);//cout<<s<<' '<<d<<endl;
ans=(ans%m+m)%m;
s=(s%m+m)%m;
d=(d%m+m)%m;
cout<<ans<<endl;
cout<<s<<' '<<d<<endl;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int tc=1;
//cin>>tc;
while(tc--)
{
solve();
}
return 0;
}
int ksm(int m,int k,int mod)
{
int ans=1;
int t=m;
while(k)
{
if(k&1) ans=ans*t%mod;
t=t*t%mod;
k>>=1;
}
return ans;
}
int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
int exgcd(int a,int b,int& x,int& y)
{
if(b==0){
x=1,y=0;
return a;//返回值为gcd(a,b)
}
int res=exgcd(b,a%b,x,y);//迭代到最底层
int t=x;
x=y;
y=t-(a/b)*y;
//完成实现时的x1=y2,y1=x2-(a/b)*y2
//由于是从最深层实现的,故直接用公式向上层传递即可
return res;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3628kb
input:
6 24 1 1 4 5 1 4
output:
1 21 9
result:
wrong answer Result not equal to solution.