QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#659101#5301. Modulo Ruins the LegendSYeaseWA 0ms3568kbC++171.6kb2024-10-19 18:38:592024-10-19 18:38:59

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 18:38:59]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3568kb
  • [2024-10-19 18:38:59]
  • 提交

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: 3568kb

input:

6 24
1 1 4 5 1 4

output:

45 -15
1
21 9

result:

wrong answer Integer parameter [name=sum] equals to 45, violates the range [0, 23]