結果

問題 No.9005 実行時間/使用メモリテスト(テスト用)
ユーザー btkbtk
提出日時 2015-06-09 04:07:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 128 ms / 3,000 ms
コード長 1,474 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 53,260 KB
実行使用メモリ 81,684 KB
最終ジャッジ日時 2023-09-20 20:07:15
合計ジャッジ時間 1,675 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
81,684 KB
testcase_01 AC 128 ms
81,404 KB
testcase_02 AC 125 ms
81,612 KB
testcase_03 AC 123 ms
81,612 KB
testcase_04 AC 124 ms
81,404 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:66:41: warning: ‘x.modset::n’ is used uninitialized in this function [-Wuninitialized]
   k = (T + (((T&x.mask)*x.ndash)&x.mask)*x.n) >> x.shift;
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~

ソースコード

diff #

#include<time.h>
#include<stdio.h>
#include<iostream>
#define N 5000000
#define LL long long
const LL mod = (LL)1e9 + 7;
LL a[N],b[N];
#define Int LL
Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}
// a x + b y = gcd(a, b)
Int extgcd(Int a, Int b, Int &x, Int &y) {
	Int g = a; x = 1; y = 0;
	if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x;
	return g;
}
Int invMod(Int a, Int m) {
	Int x, y;
	if (extgcd(a, m, x, y) == 1) return (x + m) % m;
	else                         return 0; // unsolvable
}
struct modset{
	LL n;
	LL ndash;
	LL s;
	LL mask;
	int shift;
	modset(LL n){
		n = mod;
		LL r = 1;
		shift = 0;
		while (r < n)r <<= 1, shift++;
		mask = r - 1;
		s = ((r%n)*(r%n)) % n;
		ndash = r - invMod(n, r);
	}
};
using namespace std;
const int M= (1 << 30) - 1;
int main(){
	int ss;
	cin >> ss;
	srand(ss);

	for (int i = 0; i < N; i++){
		a[i] = rand() &M;
		b[i] = rand() &M;
	}

////	clock_t st = clock();
//	for (int i = 0; i < N; i++){
//		a[i] = (a[i] * b[i]) % mod;
//	}
//	//cout << "normal:" << clock() - st << endl;
	
	modset x(mod);
	
//	st = clock();
	for (int i = 0; i < N; i++){
		LL T, k;
		T = a[i] * x.s;
		k = (T + (((T&x.mask)*x.ndash)&x.mask)*x.n) >> x.shift;
		k = (k < x.n) ? k : k - x.n;
		k *= b[i];
		k = (k + (((k&x.mask)*x.ndash)&x.mask)*x.n) >> x.shift;
		a[i] = (k < x.n) ? k : k - x.n;
		
	}
	//cout << "mong:" << clock() - st << endl;
	

	cout << 0 << endl;
}
0