結果

問題 No.2847 Birthday Attack
ユーザー 👑 kmjpkmjp
提出日時 2024-08-24 00:14:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 355 ms / 3,000 ms
コード長 1,314 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 202,224 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-08-24 00:14:25
合計ジャッジ時間 7,190 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
6,816 KB
testcase_01 AC 145 ms
6,944 KB
testcase_02 AC 155 ms
6,944 KB
testcase_03 AC 162 ms
6,944 KB
testcase_04 AC 153 ms
6,940 KB
testcase_05 AC 355 ms
6,944 KB
testcase_06 AC 251 ms
6,944 KB
testcase_07 AC 332 ms
6,940 KB
testcase_08 AC 194 ms
6,940 KB
testcase_09 AC 255 ms
6,940 KB
testcase_10 AC 204 ms
6,944 KB
testcase_11 AC 173 ms
6,940 KB
testcase_12 AC 324 ms
6,940 KB
testcase_13 AC 324 ms
6,944 KB
testcase_14 AC 275 ms
6,944 KB
testcase_15 AC 230 ms
6,944 KB
testcase_16 AC 244 ms
6,940 KB
testcase_17 AC 217 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

ll X,Y;
ll mo;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>X>>Y>>mo;
	ll ret=0;
	for(i=1;i<=4000000;i++) {
		if(X>=i*2) (ret+=(X-i*2)*(Y))%=mo;
		if(Y>=i*2) (ret+=(Y-i*2)*(X))%=mo;
	}
	for(int m=1;m*m<=8000000;m++) {
		for(int n=1;n<m;n++) {
			if(m%2!=n%2&&__gcd(m,n)==1) {
				ll a=m*m-n*n;
				ll b=2*m*n;
				for(i=1;2*a*i<=X&&2*b*i<=Y;i++) (ret+=2LL*(X-2*a*i)*(Y-2*b*i))%=mo;
				for(i=1;2*a*i<=Y&&2*b*i<=X;i++) (ret+=2LL*(Y-2*a*i)*(X-2*b*i))%=mo;
			}
		}
	}
	ret=ret*2%mo;
	cout<<ret%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0