Irreducible Polynomial(数学)

Irreducible Polynomial

题目描述

In mathematics, a polynomial is an expression consisting of variables (also called indeterminate) and coefficients, that involves only the operations of addition, subtraction, multiplication, and non-negative integer exponents of variables. For example, x2 + 4x + 7.

A polynomial is said to be irreducible if it cannot be factored into two or more non-trivial polynomials with real coefficients.
For example, x2+1 is irreducible, but x2-2x+1 is not (since x2-2x+1=(x-1)(x-1)).

Given a polynomial of degree with integer coefficients: anxn+an−1xn−1+…+a1x+a0, you need to check whether it is irreducible or not.

输入

The first line of the input gives the number of test cases, T (T≤100). test cases follow.

For each test case, the first line contains one integers n (0≤n≤20). Next line contains n + 1 integer numbers:
an,an−1,…,a1,a0
−109≤ai≤109
an≠0

输出

For each test case, output “Yes” if it is irreducible, otherwise “No”.

样例输入
2
2
1 -2 1
2
1 0 1
样例输出
No
Yes
小知识点:

n表示最高次幂,当n>=3时,都可约,当n==2时,判断b^2-4ac,若大于0,可约,否则不可约,n<2时,肯定都不能约

代码:
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int N=200010;
int T;
int main()
{
	//注意不可约输出Yes 
	cin>>T;
	while(T--){
		int n,a[110],f=0;
		cin>>n;
		for(int i=1;i<=n+1;i++) cin>>a[i];
		if(n>2) f=1;
		if(n==2){
			if(a[2]*a[2]-4*a[1]*a[3]>=0) f=1;
		}
		if(f==0) cout<<"Yes\n";
		else cout<<"No\n";
	}
	return 0;
} 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是Berlekamp算法的matlab实现: function [factors] = berlekamp(poly) % BERLEKAMP algorithm for factorization of polynomials over Galois % field GF(2^n). % % Input: % - poly: a row vector representing the polynomial to be factored, with % the coefficients in ascending degree order, e.g. [1 0 1 1] for % x^3 + x + 1. % % Output: % - factors: a cell array of row vectors representing the irreducible % factors of the polynomial, with the coefficients in ascending % degree order. n = length(poly) - 1; factors = {}; % Set up the Berlekamp matrix. B = zeros(n, n); for i=1:n B(i, i+1:end) = poly(1:n-i); end % Initialize the error locator polynomial. sigma = [1 zeros(1, n)]; % Initialize the discrepancy sequence. delta = zeros(1, n+1); delta(1) = 1; % Initialize the error evaluator polynomial. psi = [1 0]; % Set up the alpha vector. alpha = zeros(1, n); for i=0:n-1 alpha(i+1) = 2^i; end % Main loop. for i=1:n % Compute the discrepancy. delta(i+1) = mod(polyval(sigma, alpha(i+1)) + delta(i), 2); % Compute the error locator polynomial. if delta(i+1) == 0 % No error, so no update needed. sigma = mod(conv(sigma, [1 0]), 2); else % Update sigma. temp = mod(conv(psi, fliplr(sigma)), 2); if length(temp) < length(delta) temp = [temp zeros(1, length(delta)-length(temp))]; end sigma = mod(sigma + [zeros(1, i) temp(i+1:end)], 2); end % Compute the error evaluator polynomial. psi = mod(conv(fliplr(delta(1:i+1)), sigma), 2); % Check for irreducibility. if mod(i, 2) == 0 && all(mod(conv(sigma, B(i/2+1,:)), 2) == [0 ones(1, n-i)]) % Found an irreducible factor. factors{end+1} = sigma; % Update poly. poly = mod(conv(poly, sigma), 2); n = length(poly) - 1; if n == 0 % poly is now 1, so we're done. return; end % Update B. B = zeros(n, n); for j=1:n B(j, j+1:end) = poly(1:n-j); end % Update sigma, delta, psi, alpha. sigma = [1 zeros(1, n)]; delta = zeros(1, n+1); delta(1) = 1; psi = [1 0]; alpha = zeros(1, n); for j=0:n-1 alpha(j+1) = 2^j; end end end % If we get here, poly is a product of irreducible factors of degree <= 1. for i=1:n if poly(i) == 1 factors{end+1} = [1 zeros(1, i-1)]; end end end 使用示例: >> poly = [1 1 1 0 1]; % x^4 + x^3 + x + 1 >> factors = berlekamp(poly) factors = [1 1 1] [1 0 1] 这表示x^4 + x^3 + x + 1 = (x^2 + x + 1)(x^2 + 1)。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值