[ARC158D] Equation
Problem Statement
You are given a positive integer $n$, and a prime number $p$ at least $5$.
Find a triple of integers $(x,y,z)$ that satisfies all of the following conditions.
- $1\leq x < y < z \leq p - 1$.
- $(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) \equiv x^{3n}+y^{3n}+z^{3n}\pmod{p}$.
It can be proved that such a triple $(x,y,z)$ always exists.
You have $T$ test cases to solve.
Constraints
- $1\leq T\leq 10^5$
- $1\leq n\leq 10^9$
- $p$ is a prime number satisfying $5\leq p\leq 10^9$.
Input
The input is given from Standard Input in the following format:
$T$
$\text{case}_1$
$\vdots$
$\text{case}_T$
Each case is in the following format:
$n$ $p$
Output
Print $T$ lines. The $i$-th line should contain $x,y,z$ with spaces in between where $(x,y,z)$ is a solution for the $i$-th test case.
If multiple solutions exist, you may print any of them.
Sample Input 1
3
1 7
2 7
10 998244353
Sample Output 1
1 4 6
1 2 5
20380119 21549656 279594297
For the first test case:
- $(x+y+z)(x^n+y^n+z^n)(x^{2n}+y^{2n}+z^{2n}) = (1+4+6)(1+4+6)(1+16+36) = 6413$, and
- $x^{3n}+y^{3n}+z^{3n} = 1 + 64 + 216 = 281$.
We have $6413\equiv 281\pmod{7}$, so the conditions are satisfied.
本来以为拆开有什么用,后来又发现没有。
但是观察到两边是不齐次的,也就是说,如果设 \(x=ta%p,y=tb%p,z=tc%p\),那么我们可以随机出一个 \(a,b,c\),然后是可以解出 \(t\) 的
具体而言,设算出来左式= \(t^{6n}\times d\),右式为 \(t^{3n}\times e\),那么知道了 \(d\) 和 \(e\),可以解出 \(t\)
那么 \(d\) 和 \(e\) 要满足什么要求可以解出 \(t\) 呢?只要不都是 0 就行了。随机出来 \(a,b,c\),就可以算出 \(d\) 和 \(e\),容易发现,\(d\) 和 \(e\) 大概率不是0.
#include<bits/stdc++.h>
using namespace std;
int n,p,TME;
long long x,y,z,a,b,c,d,e,f,g;
mt19937_64 gen(time(0)) ;
long long pw(int x,long long y)
{
if(!y)
return 1;
long long t=pw(x,y>>1);
if(y&1)
return t*t%p*x%p;
return t*t%p;
}
int main()
{
scanf("%d",&TME);
while(TME--)
{
scanf("%d%d",&n,&p);
while(1)
{
x=gen()%(p-1)+1,y=gen()%(p-1)+1,z=gen()%(p-1)+1;
if(x^y&&y^z&&z^x&&(x+y+z)%p&&(a=pw(x,n)+pw(y,n)+pw(z,n))%p&&(b=pw(x,n+n)+pw(y,n+n)+pw(z,n+n))%p&&(c=pw(x,n*3LL)+pw(y,n*3LL)+pw(z,n*3LL))%p)
{
d=(x+y+z)%p*a%p*b%p;
c=c*pw(d,p-2)%p;
e=c*x%p,f=c*y%p,g=c*z%p;
if(e>f)
swap(e,f);
if(e>g)
swap(e,g);
if(f>g)
swap(f,g);
printf("%lld %lld %lld\n",e,f,g);
break;
}
}
}
}
[ARC158D] Equation的更多相关文章
- CodeForces460B. Little Dima and Equation
B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...
- ACM: FZU 2102 Solve equation - 手速题
FZU 2102 Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & ...
- HDU 5937 Equation
题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...
- coursera机器学习笔记-多元线性回归,normal equation
#对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...
- CF460B Little Dima and Equation (水题?
Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...
- Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)
,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...
- ACM:HDU 2199 Can you solve this equation? 解题报告 -二分、三分
Can you solve this equation? Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- [ACM_数学] Counting Solutions to an Integral Equation (x+2y+2z=n 组合种类)
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=27938#problem/E 题目大意:Given, n, count the numbe ...
- hdu 2199 Can you solve this equation?(二分搜索)
Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ( ...
- SGU 106 The equation
H - The equation Time Limit:250MS Memory Limit:4096KB 64bit IO Format:%I64d & %I64u Subm ...
随机推荐
- Netty源码学习3——Channel ,ChannelHandler,ChannelPipeline
系列文章目录和关于我 零丶引入 在Netty源码学习2--NioEventLoop的执行中,我们学习了NioEventLoop是如何进行事件循环以及如何修复NIO 空轮询的bug的,但是没有深入了解I ...
- MFC中使用函数实现ini文件的连续读写
实现的思路: 首先通过读取文件中的count值,确定当前信息条数: 第二步:将count进行累加,把信息写到累加后的键值"="的后面: 第三步:写入count累加值,实现连续读写: ...
- Docker Swarm + Harbor + Portainer 打造高可用,高伸缩,集群自动化部署,更新。
Docker Swarm是Docker官方自带的容器编排工具,Swarm,Compose,Machine合称Docker三剑客.Docker Swarm对于中小型应用来说,还是比较方便,灵活,当然K8 ...
- 编译nw-node版本的插件
编译nw-node版本的插件 下载nwjs对应版本的nodejs 原始源码目录 yh@yh:~/addon$ tree . ├── addon.cc ├── binding.gyp ├── CppLi ...
- Python 列表操作指南3
示例,将新列表中的所有值设置为 'hello': newlist = ['hello' for x in fruits] 表达式还可以包含条件,不像筛选器那样,而是作为操纵结果的一种方式: 示例,返回 ...
- Python中的转义符\
1.转义符 可以百度百科查询 2.Python中的转义符 我目前知道的Python中的转义符使用场景有两个:一个是字符串,一个是正则表达式 2.1.字符串的转义 2.1.1.反斜杠"\&qu ...
- ElasticSearch系列——查询、Python使用、Django/Flask集成、集群搭建,数据分片、位置坐标实现附近的人搜索
@ 目录 Elasticsearch之-查询 一 基本查询 1.1 match查询 1.2 term查询 1.3 terms查询 1.4 控制查询的返回数量(分页) 1.5 match_all 查询 ...
- mooc第五单元《管理组织》单元测试
第五单元<管理组织>单元测试 返回 本次得分为:30.00/50.00, 本次测试的提交时间为:2020-08-30, 如果你认为本次测试成绩不理想,你可以选择 再做一次 . 1 ...
- Makefile 入门教程
Makefile 是一个非常强大的构建自动化工具,用于管理项目的编译.链接和其他构建任务.以下是一个详细的 Makefile 使用文档,包括基本概念.语法.示例和常见任务. 1. 基本概念 目标 (T ...
- 重温dp——最长上升公共子序列
一道经典的dp了 题目描述 给出 1,2,-,n 的两个排列 P1 和 P2 ,求它们的最长公共子序列. 输入格式 第一行是一个数 n. 接下来两行,每行为 n 个数,为自然数 1,2,-,n 的一 ...