poj 1060 Modular multiplication of polynomials
方法(无证明,lz弱渣请谅解):
以样例来讲:(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 。
令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;
求a/b的余数,首先b*x^(13-8),由于系数为0或1,所以a= b*(x^(13-8))异或a=x^11+x^4+x^3+1
11>8重复上述步骤:a= b*(x^(11-8))异或 a=x^7+x^6+x^5+1
7<8得结构,因此(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
主要就这个不好做,其他都好写
#include <iostream> #include <cstdio> #include <cstring>using namespace std; const int maxn=2010; //f,g,h存储的是多项式的系数,sum存储的是f*g的系数以及最后余数的系数 int f[maxn],g[maxn],h[maxn],sum[maxn]; int lf,lg,lh,ls;//分别为f,g,h,sum的最高次幂//比较sum表示的多项式与h表示的多项式的大小 int compare() {if(ls<lh)return -1;if(ls>lh)return 1;for(int i=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; } int main() {int t,d;scanf("%d",&t);while(t--) {memset(h,0,sizeof(h));memset(sum,0,sizeof(sum));//将f多项式的信息存入f数组scanf("%d",&d);lf=d-1;for(int j=lf; j>=0; j--) {scanf("%d",&f[j]);}//将g多项式的信息存入g数组scanf("%d",&d);lg=d-1;for(int j=lg; j>=0; j--) {scanf("%d",&g[j]);}//将h多项式的信息存入h数组scanf("%d",&d);lh=d-1;for(int j=lh; j>=0; j--) {scanf("%d",&h[j]);}//计算f*g的多项式ls=lf+lg;for(int i=lf; i>=0; i--) {for(int j=lg; j>=0; j--) {sum[i+j]=sum[i+j]^(f[i]&g[j]);}}/*关键是怎么求余数,这里是先判断sum多项式是否大于h多项式,若大于,则sum减一次h,减去后的信息存入sum中。再继续判断,直到sum小于h,则此时的sum为余数。总之,就是把除法改成较简单的减法操作。*/while(compare()>=0) {d=ls-lh;for(int i=ls; i-d>=0; i--) {sum[i]=sum[i]^h[i-d];}while(ls && !sum[ls])ls--;}printf("%d",ls+1);for(int i=ls; i>=0; i--) {printf(" %d",sum[i]);}printf("\n");}return 0; }
参考http://www.cnblogs.com/chenxiwenruo/p/3332698.html
转载于:https://www.cnblogs.com/Scale-the-heights/p/4351887.html
poj 1060 Modular multiplication of polynomials相关推荐
- 1026 Modular multiplication of polynomials
这道题目是多项式相乘.求模..按照题目中的规则,可以看出,多项式的加法和减法是相同的结果,那么多项式的除法都可以用加法来计算了.代码的重点是21到24行,36到37行,是如何实现乘和求余的步骤. 1 ...
- POJ1060 HDU1343 ZOJ1026 UVALive2323 Modular multiplication of polynomials题解
代码来源:DeathYmz AC的C++语言程序如下: #include<cstdio> #include<iostream> #include<cstring> ...
- 基础算法优化——Fast Modular Multiplication
1. 引言 Yuval Domb 2022年论文<Fast Modular Multiplication> 模乘可以说是任何密码系统中计算量最大的算术原语.本文提出了一种高效.硬件友好的算 ...
- 牛客国庆集训派对Day5B电音之王(Montgomery modular multiplication)
Montgomery modular multiplication 代码出处min_25 杜教暑期时候讲过(我不懂但是我会贴代码呀.jpg),正好牛客网放了camp的题目,那就mark一下 优秀的卡常 ...
- 【POJ - 1651】Multiplication Puzzle(区间dp)
题干: The multiplication puzzle is played with a row of cards, each containing a single positive integ ...
- POJ前面的题目算法思路【转】
1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 85% 2005-5-7 1002 487-3279 n/a 90% 2005-5- ...
- POJ 超详细分类
POJ 各题算法 1000 A+B Problem 送分题 49% 2005-5-7 1001 Exponentiation 高精度 ...
- poj题目详细分类及算法推荐题目
DP: 1011 NTA 简单题 1013 Great Equipment 简单题 1024 Calendar Game 简单题 ...
- ACM POJ 题目分类(完整整理版本)
DP: 1011 NTA 简单题 1013 Great Equipment 简单题 1024 Calendar Game 简单题 ...
最新文章
- android:listView Button 焦点问题
- 【Oracle】触发器最系统入门学习指导
- BCI2000对win10的支持
- json文件转为excel_2分钟上手、3小时学会无代码软件开发---XML、Json处理
- Spring框架学习笔记02:初探Spring——利用组件注解符精简Spring配置文件
- spark 序列化错误 集群提交时_Spark统一内存管理机制
- 漫画:为什么你需要了解数据结构中的图?
- vscode如何关闭Pylint警告或错误提示
- RabbitMQ基础知识详解
- js 加入收藏,设为首页
- 软件开发中的时区问题
- 美国佐治亚理工计算机专业,世界大学排名之:美国佐治亚理工学院
- 当代科技哲学课后阅读材料摘录——朱清时谈佛法与科学
- Ubuntu系统配置花生壳内网穿透
- Matlab点云处理及可视化第1期—基于KD树的邻域点搜索(柱状邻域、球状邻域及KNN)
- xp2 server application error 错误解决
- wsctf.exe病毒专杀
- VC6工程升级VS2013汇总
- 测量平差之附有限制条件的条件平差(概括平差模型)
- github 报错提示 ERROR: You‘re using an RSA key with SHA-1