[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 ...
随机推荐
- 【RocketMQ】MQ消息发送总结
RocketMQ是通过DefaultMQProducer进行消息发送的,它实现了MQProducer接口,MQProducer接口中定义了消息发送的方法,方法主要分为三大类: send同步进行消息发送 ...
- 9、Mybatis之动态SQL
9.1.环境搭建 9.1.1.创建新module 创建名为mybatis_dynamicSQL的新module,过程参考5.1节 9.1.2.创建Emp实体类 package org.rain.myb ...
- 千万级数据深分页查询SQL性能优化实践
一.系统介绍和问题描述 如何在Mysql中实现上亿数据的遍历查询?先来介绍一下系统主角:关注系统,主要是维护京东用户和业务对象之前的关注关系:并对外提供各种关系查询,比如查询用户的关注商品或店铺列表, ...
- CodeForces 1367F1 Flying Sort (Easy Version)
题意 给一个长度为\(n\)的数组,数组中的数互不相同,你可以有两种操作 将某一个数放置在数组开头 将某一个数放置在数组结尾 问最小操作多少次可以得到一个递增数列 分析 因为数组中的数很大,我们可以将 ...
- 如何解决IOS 15提示“此App的开发者需要更新APP以在此IOS版本上正常工作”, 无法打开安装的APP的问题
在苹果手机最新的IOS 15 beta的系统上安装自签名或者企业签名的APP时,可能会遇到如下的错误提示: 此App的开发者需要更新APP以在此IOS版本上正常工作 The developer of ...
- Kafka Stream 流和状态
4.2将状态操作应用到Kafka Stream 在上图的拓扑中生成了一个购买-交易事件流,拓扑中的一个处理节点根据销售额来计算客户的奖励级分.但在这个处理其中,要做的也仅仅时计算单笔交易的总积分,并转 ...
- 基于 ActionFilters 的限流库DotNetRateLimiter使用
前言 在构建API项目时,有时出于安全考虑,防止访问用户恶意攻击,希望限制此用户ip地址的请求次数,减轻拒绝服务攻击可能性,也称作限流.接下来,我们就来学习开源库DotNetRateLimiter 如 ...
- python爬虫——爬取天气预报信息
在本文中,我们将学习如何使用代理IP爬取天气预报信息.我们将使用 Python 编写程序,并使用 requests 和 BeautifulSoup 库来获取和解析 HTML.此外,我们还将使用代理服务 ...
- burpsuite验证码爆破后台夺权
目录 准备工作 爆破 同时爆破用户名密码和验证码 筛查爆破结果的成功输出 创建新用户远程桌面连接 准备工作 安装python 安装muggle_ocr库 运行xp_CAPTCHA服务端 burpsui ...
- 使用 OpenTelemetry 构建 .NET 应用可观测性(3):.NET SDK 概览
目录 前言 概览 opentelemetry-dotnet opentelemetry-dotnet-contrib opentelemetry-dotnet-instrumentation SDK ...