[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 ...
随机推荐
- 1、Spring简介
1.1.概述 Spring 是轻量级的框架,其基础版本只有 2 MB 左右的大小. Spring 框架是一个开源的 Java 平台,它最初是由 Rod Johnson 编写的,并且于 2003 年 6 ...
- VictoriaLogs:一款超低占用的 ElasticSearch 替代方案
背景 前段时间我们想实现 Pulsar 消息的追踪流程,追踪实现的效果图如下: 实现其实比较简单,其中最重要的就是如何存储消息. 消息的读取我们是通过 Pulsar 自带的 BrokerInterce ...
- CentOS 内网YUM源配置使用
YUM介绍 yum,是Yellow dog Updater, Modified 的简称,是杜克大学为了提高RPM 软件包安装性而开发的一种软件包管理器.起初是由yellow dog 这一发行版的开发者 ...
- LeetCode 周赛上分之旅 #43 计算机科学本质上是数学吗?
️ 本文已收录到 AndroidFamily,技术和职场问题,请关注公众号 [彭旭锐] 和 BaguTree Pro 知识星球提问. 学习数据结构与算法的关键在于掌握问题背后的算法思维框架,你的思考越 ...
- Falcon-7B大型语言模型在心理健康对话数据集上使用QLoRA进行微调
文本是参考文献[1]的中文翻译,主要讲解了Falcon-7B大型语言模型在心理健康对话数据集上使用QLoRA进行微调的过程.项目GitHub链接为https://github.com/iamaru ...
- 2023 ICPC 网络赛 I
没留够时间准备导致开考的时候耽搁了 开场我先写缺省源,抄串了一行,后面才发现...然后看了 L 发现是签到,此时 ddw 会了 A 让 zsy 上去写,我等了一会才把 zsy 撵下来写 L 是个失误 ...
- math库常用函数+产生随机数总结
math库常用函数+产生随机数总结 1.对x开平方 double sqrt(x)://返回值为double类型,输入的x类型随意,只要是数的类型 2.求常数e的x次方 double exp(x);// ...
- 为.NET打开新大门:OpenVINO.NET开源项目全新发布
为.NET打开新大门:OpenVINO.NET开源项目全新发布 在AI的应用越来越广泛的今天,优化深度学习模型并进行推理部署已经成为了一门必要的技术.Intel开发的OpenVINO工具包(Open ...
- ELK+ filebeat
ELK 企业级日志分析系统 ELK 概述 1.ELK 简介 ELK平台是一套完整的日志集中处理解决方案,将 ElasticSearch.Logstash 和 Kiabana 三个开源工具配合使用, 完 ...
- Go 函数的健壮性、panic异常处理、defer 机制
Go 函数的健壮性.panic异常处理.defer 机制 目录 Go 函数的健壮性.panic异常处理.defer 机制 一.函数健壮性的"三不要"原则 1.1 原则一:不要相信任 ...