Codeforce-CodeCraft-20 (Div. 2)-C. Primitive Primes(本原多项式+数学推导)
It is Professor R’s last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.
You are given two polynomials f(x)=a0+a1x+⋯+an−1xn−1 and g(x)=b0+b1x+⋯+bm−1xm−1, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to 1 for both the given polynomials. In other words, gcd(a0,a1,…,an−1)=gcd(b0,b1,…,bm−1)=1. Let h(x)=f(x)⋅g(x). Suppose that h(x)=c0+c1x+⋯+cn+m−2xn+m−2.
You are also given a prime number p. Professor R challenges you to find any t such that ct isn’t divisible by p. He guarantees you that under these conditions such t always exists. If there are several such t, output any of them.
As the input is quite large, please use fast input reading methods.
Input The first line of the input contains three integers, n, m and p (1≤n,m≤106,2≤p≤109), — n and m are the number of terms in f(x) and g(x) respectively (one more than the degrees of the respective polynomials) and p is the given prime number.
It is guaranteed that p is prime.
The second line contains n integers a0,a1,…,an−1 (1≤ai≤109) — ai is the coefficient of xi in f(x).
The third line contains m integers b0,b1,…,bm−1 (1≤bi≤109) — bi is the coefficient of xi in g(x).
Output Print a single integer t (0≤t≤n+m−2) — the appropriate power of x in h(x) whose coefficient isn’t divisible by the given prime p. If there are multiple powers of x that satisfy the condition, print any.
Examples inputCopy 3 2 2 1 1 2 2 1 outputCopy 1 inputCopy 2 2 999999937 2 1 3 1 outputCopy 2 Note In the first test case, f(x) is 2x2+x+1 and g(x) is x+2, their product h(x) being 2x3+5x2+3x+2, so the answer can be 1 or 2 as both 3 and 5 aren’t divisible by 2.
In the second test case, f(x) is x+2 and g(x) is x+3, their product h(x) being x2+5x+6, so the answer can be any of the powers as no coefficient is divisible by the given prime.
题意: 给定两个多项式长度 n 和 m ,再给定每一项的系数,由常数项到最高次项排序,其中每个多项式的系数的GCD=1。
然后再给定一个质数 p
问两个多项式相乘后得到的第三个多项式中,哪一项的系数不是 p 的倍数,输出这个项的x的幂次(下标)
可行性:本原多项式 如果还有问题的话,欢迎DL补充,小弟不胜感激,洗耳恭听。
#include <bits/stdc++.h>
using namespace std;
template <typename t>
void read(t &x)
{
char ch = getchar();
x = 0;
t f = 1;
while (ch < '0' || ch > '9')
f = (ch == '-' ? -1 : f), ch = getchar();
while (ch >= '0' && ch <= '9')
x = x * 10 + ch - '0', ch = getchar();
x *= f;
}
#define wi(n) printf("%d ", n)
#define wl(n) printf("%lld ", n)
#define rep(m, n, i) for (int i = m; i < n; ++i)
#define rrep(m, n, i) for (int i = m; i > n; --i)
#define P puts(" ")
typedef long long ll;
#define MOD 1000000007
#define mp(a, b) make_pair(a, b)
#define N 200005
#define fil(a, n) rep(0, n, i) read(a[i])
//---------------https://lunatic.blog.csdn.net/-------------------//
int main()
{
int m, n, p, tem;
read(n), read(m), read(p);
ll ans1 = 0, ans2 = 0;
for (int i = 0; i < n; i++)
{
read(tem);
tem %= p;
if (tem && !ans1)
ans1 = i;
}
for (int i = 0; i < m; i++)
{
read(tem);
tem %= p;
if (tem && !ans2)
ans2 = i;
}
cout << ans1 +ans2 << endl;
}
写在最后: 我叫风骨散人,名字的意思是我多想可以不低头的自由生活,可现实却不是这样。家境贫寒,总得向这个世界低头,所以我一直在奋斗,想改变我的命运给亲人好的生活,希望同样被生活绑架的你可以通过自己的努力改变现状,深知成年人的世界里没有容易二字。目前是一名在校大学生,预计考研,热爱编程,热爱技术,喜欢分享,知识无界,希望我的分享可以帮到你! 如果有什么想看的,可以私信我,如果在能力范围内,我会发布相应的博文! 感谢大家的阅读!?你的点赞、收藏、关注是对我最大的鼓励!
- 如何解决打开VS2010后没有UI界面的问题
- RadRails1.0降临——增加Profiler、CallGraph Analyzer和Rails Shell等新特性
- Rails存储库从SVN转向Git
- 报告称10后已变成出境游“老司机”屌丝80后:我还没出过国
- 担心人工智能取代你的工作?听听微软科学家怎么说!
- Radiant: 基于Ruby on Rails的内容管理系统
- “大数据”如何追回1.3亿元税款?
- Enterprise Library深入解析与灵活应用(5):创建一个简易版的批处理执行器,认识Enterprise Library典型的配置方式和对象创建方式
- BTC.com时讯-IBM等老牌大企业因区块链技术获得新活力
- Kit 3D 更新
- Enterprise Library深入解析与灵活应用(5):创建一个简易版的批处理执行器,认识Enterprise Library典型的配置方式和对象创建方式
- 晚上好啊!这是今天人工智能精选要闻
- 构建Flex应用的10大误区
- Flex的起步推动新语言学习
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- [解决]Docker中安装Centos7后无法正常使用命令
- 毕业设计之「测试实验及结果分析」(一)
- 【DB笔试面试845】在Oracle中,sqlnet.ora文件的作用是什么?
- 安卓-无敌解决ListView添加标题头无法正常显示的问题(歪门邪道)
- 贪心算法-活动选择问题(Python实现)
- 浅析C语言中一些“令人吃惊”的结构
- 贪心算法-分数背包问题(Python实现)
- 为什么GNE 不做全自动提取列表页的功能
- 百度地图开发如何自定义控件(无敌的解决办法)
- 百度地图如何创建一个属于自己的地图,附加到项目中?
- FreeRTOS系列第9篇---FreeRTOS任务概述基础篇
- 图书管理系统(四)图书管理系统实战(2)
- 源码分析之 FactoryBean接口不为人知的秘密
- 图书管理系统(三)图书管理系统实战(1)
- 图书管理系统(二)整合 SSM,你学会了么