POJ 1060 Modular multiplication of polynomials

Source: Internet
Author: User

Method (no proof, LZ weak slag please understand):

In the example: (x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) modulo (x^8 + x^4 + x^3 + x + 1) = x^7 + x^6 + 1.

(x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) =x^13 + x^11 + x^9 + x^8 + x^6 + x^5 + x^4 + x^3 + 1.

Make a=x^13 + x^11 + x^9 + x^8 + x^6 + x^5 + x^4 + x^3 + 1, b=x^8 + x^4 + x^3 + x + 1;

For the remainder of A/b, first b*x^ (13-8), since the coefficients are 0 or 1, so a= b* (x^ (13-8)) XOR a=x^11+x^4+x^3+1

11>8 Repeat the steps above: a= b* (x^ (11-8)) XOR a=x^7+x^6+x^5+1

7<8 structure, therefore (x^6 + x^4 + x^2 + x + 1) (x^7 + x + 1) modulo (x^8 + x^4 + x^3 + x + 1) = x^7 + x^6 + 1= x^7+x^6+x^5+1

This is not the main thing to do, the others are good to write

#include <iostream>#include<cstdio>#include<cstring>using namespacestd;Const intmaxn= .;//F,g,h stores the coefficients of the polynomial, sum stores the coefficients of the f*g and the coefficients of the last remainder.intF[MAXN],G[MAXN],H[MAXN],SUM[MAXN];intLf,lg,lh,ls;//the highest power of the F,g,h,sum, respectively.//Compare the size of the polynomial represented by the sum with the H representation of the polynomialintCompare () {if(ls<LH)return-1; if(ls>LH)return 1;  for(inti=ls-1; i>=0; i--) {        if(sum[i]==H[i])Continue; if(sum[i]>H[i])return 1; if(sum[i]<H[i])return-1; }    return 0;}intMain () {intt,d; scanf ("%d",&t);  while(t--) {memset (H,0,sizeof(h)); memset (SUM,0,sizeof(sum)); //depositing the information of the F-polynomial into the F-arrayscanf"%d",&d); LF=d-1;  for(intJ=LF; j>=0; j--) {scanf ("%d",&F[j]); }        //The G-polynomial information is stored in the G arrayscanf"%d",&d); LG=d-1;  for(intJ=LG; j>=0; j--) {scanf ("%d",&G[j]); }        //The H -polynomial information is stored in the H arrayscanf"%d",&d); LH=d-1;  for(intJ=LH; j>=0; j--) {scanf ("%d",&H[j]); }        //polynomial for calculating f*gls=lf+LG;  for(intI=LF; i>=0; i--) {             for(intJ=LG; j>=0; j--) {Sum[i+j]=sum[i+j]^ (f[i]&G[j]); }        }        /*The key is how to find the remainder, here is the first to determine whether the sum polynomial is greater than the H polynomial, if greater than, then sum minus one time H, minus the information into sum.          Continue judging until sum is less than H, then the sum is the remainder.        In short, it is to change the division to a simpler subtraction operation. */         while(Compare () >=0) {D=ls-LH;  for(intI=ls; i-d>=0; i--) {Sum[i]=sum[i]^h[i-d]; }             while(LS &&!)sum[ls]) LS--; } printf ("%d", ls+1);  for(intI=ls; i>=0; i--) {printf ("%d", Sum[i]); } printf ("\ n"); }    return 0;}

Reference http://www.cnblogs.com/chenxiwenruo/p/3332698.html

POJ 1060 Modular multiplication of polynomials

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.