cp-library

競技プログラミング用 C++ ライブラリ

View the Project on GitHub qandori/cp-library

:heavy_check_mark: test/fps_light_polynomial_extended_gcd.test.cpp

test/fps_light_polynomial_extended_gcd.test.cpp · GitHub で見る

検証問題

依存ライブラリ

コード

#define PROBLEM "https://judge.yosupo.jp/problem/inv_of_polynomials"
#include "fps/polynomial_gcd_light.hpp"
#include "fixtures/fps_light_io.hpp"

int main() {
	FastInput input;
	FastOutput output;
	int n = 0, m = 0;
	input.read(n), input.read(m);
	light_fps a = read_light_fps(input, n), b = read_light_fps(input, m);
	auto result = light_fps_algorithms::polynomial_extended_gcd(std::move(a), b);
	if (m > 1 && result.gcd.size() != 1) { output.println(-1); return 0; }
	auto inverse = result.x.divmod(b).second;
	output.println(inverse.size());
	write_light_fps(output, inverse);
}
Back to top page