結果
| 問題 |
No.2847 Birthday Attack
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 22:01:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 461 ms / 3,000 ms |
| コード長 | 959 bytes |
| コンパイル時間 | 908 ms |
| コンパイル使用メモリ | 74,872 KB |
| 実行使用メモリ | 160,608 KB |
| 最終ジャッジ日時 | 2024-08-23 22:01:47 |
| 合計ジャッジ時間 | 8,957 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
39 | for(auto[a,b]:T)
| ^
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
using namespace std;
int gcd(int a,int b)
{
while(b)
{
int t=a%b;
a=b;
b=t;
}
return a;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
vector<pair<int,int> >T;
T.reserve(20138910);
auto add=[&](int a,int b){
int mxab=max(a,b);
for(int k=1;mxab*k<=(int)4e6;k++)T.emplace_back(a*k,b*k);
};
for(int m=1;m*m<=(int)6e6;m++)
{
for(int n=1;n<m;n++)
{
if(n%2&&m%2)continue;
if(gcd(n,m)!=1)continue;
add(m*m-n*n,2*m*n);
add(2*m*n,m*m-n*n);
}
}
int X,Y,M;
cin>>X>>Y>>M;
long ans=0;
for(auto[a,b]:T)
{
int lx=a+1,rx=X-a;
int ly=b+1,ry=Y-b;
if(lx>rx||ly>ry)continue;
ans+=(long)(rx-lx+1)*(ry-ly+1)%M;
if(ans>=M)ans-=M;
}
ans=ans*4%M;
for(int a=1;a+1<=X-a;a++)
{
ans+=(long)(X-a-a-1+1)*Y*2%M;
if(ans>=M)ans-=M;
}
for(int b=1;b+1<=Y-b;b++)
{
ans+=(long)X*(Y-b-b-1+1)*2%M;
if(ans>=M)ans-=M;
}
cout<<ans<<endl;
}