QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#751443#5301. Modulo Ruins the LegendYangHyyyWA 25ms3644kbC++23664b2024-11-15 18:44:322024-11-15 18:44:33

Judging History

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

  • [2024-11-15 18:44:33]
  • 评测
  • 测评结果:WA
  • 用时:25ms
  • 内存:3644kb
  • [2024-11-15 18:44:32]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int exgcd(int a, int b, int &x, int &y)
{
    if (!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    int d = exgcd(b, a % b, y, x);
    y -= (a / b) * x;
    return d;
}
int main()
{
	int n,m,tmp,sum=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>tmp;
		sum+=tmp;
	}
	int a=n,b=n*(n+1)/2;
	int g1=gcd(a,b);
	int g2=gcd(g1,m);
	int x,y,k1,t;
	int ans=sum%g2;
	exgcd(g1,m,k1,t);
	k1*=((ans-sum)/g2)%m;
	k1%=m;
	
	exgcd(a,b,x,y);
	x*=k1,y*=k1;
	cout<<ans<<endl;
	cout<<(x%m+m)%m<<" "<<(y%m+m)%m<<endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3644kb

input:

6 24
1 1 4 5 1 4

output:

1
15 19

result:

ok ok

Test #2:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

7 29
1 9 1 9 8 1 0

output:

0
0 0

result:

ok ok

Test #3:

score: 0
Accepted
time: 0ms
memory: 3632kb

input:

1 1
0

output:

0
0 0

result:

ok ok

Test #4:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

1 1000000000
963837005

output:

0
0 36162995

result:

ok ok

Test #5:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

2 1
0 0

output:

0
0 0

result:

ok ok

Test #6:

score: 0
Accepted
time: 0ms
memory: 3640kb

input:

2 1000000000
948507269 461613424

output:

0
410120693 589879307

result:

ok ok

Test #7:

score: 0
Accepted
time: 9ms
memory: 3616kb

input:

100000 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

0
0 0

result:

ok ok

Test #8:

score: -100
Wrong Answer
time: 25ms
memory: 3564kb

input:

100000 1000000000
253614966 278270960 980235895 498158918 928430170 216003119 852570558 948400590 239257296 897053667 294741176 38297441 382677590 406314557 609468973 854148232 314532767 738191551 158215002 5865825 920471826 380037058 356271728 749175327 28319049 208101105 953758995 896570758 521930...

output:

5
304709556 545805724

result:

wrong answer Result not equal to solution.