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的更多相关文章

  1. CodeForces460B. Little Dima and Equation

    B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input s ...

  2. ACM: FZU 2102 Solve equation - 手速题

     FZU 2102   Solve equation Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & ...

  3. HDU 5937 Equation

    题意: 有1~9数字各有a1, a2, -, a9个, 有无穷多的+和=. 问只用这些数字, 最多能组成多少个不同的等式x+y=z, 其中x,y,z∈[1,9]. 等式中只要有一个数字不一样 就是不一 ...

  4. coursera机器学习笔记-多元线性回归,normal equation

    #对coursera上Andrew Ng老师开的机器学习课程的笔记和心得: #注:此笔记是我自己认为本节课里比较重要.难理解或容易忘记的内容并做了些补充,并非是课堂详细笔记和要点: #标记为<补 ...

  5. CF460B Little Dima and Equation (水题?

    Codeforces Round #262 (Div. 2) B B - Little Dima and Equation B. Little Dima and Equation time limit ...

  6. Linear regression with multiple variables(多特征的线型回归)算法实例_梯度下降解法(Gradient DesentMulti)以及正规方程解法(Normal Equation)

    ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, ,, , ...

  7. 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 ...

  8. [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 ...

  9. hdu 2199 Can you solve this equation?(二分搜索)

    Can you solve this equation? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  10. SGU 106 The equation

    H - The equation Time Limit:250MS     Memory Limit:4096KB     64bit IO Format:%I64d & %I64u Subm ...

随机推荐

  1. 一次Java内存占用高的排查案例,解释了我对内存问题的所有疑问

    原创:扣钉日记(微信公众号ID:codelogs),欢迎分享,非公众号转载保留此声明. 问题现象 7月25号,我们一服务的内存占用较高,约13G,容器总内存16G,占用约85%,触发了内存报警(阈值8 ...

  2. PicGo+Github图床配置

    为了将 PicGo 设置为使用 GitHub 作为图床,您需要先创建一个 GitHub 仓库用于存储图片,然后在 PicGo 中进行相应的配置.您已经创建了一个仓库,所以让我们来配置 PicGo. 安 ...

  3. 基于ASP.NET ZERO,开发SaaS版供应链管理系统

    前言 在园子吸收营养10多年,一直没有贡献,目前园子危机时刻,除了捐款+会员,也鼓起勇气,发篇文助力一下. 2018年下半年,公司决定开发一款SaaS版行业供应链管理系统,经过选型,确定采用ABP(A ...

  4. MQ系列14:MQ如何做到消息延时处理

    MQ系列1:消息中间件执行原理 MQ系列2:消息中间件的技术选型 MQ系列3:RocketMQ 架构分析 MQ系列4:NameServer 原理解析 MQ系列5:RocketMQ消息的发送模式 MQ系 ...

  5. springboot下载文件 范围下载

    springboot下载文件 范围下载 关键词:springboot,download,Range,Content-Range,Content-Length,http code 206 Partial ...

  6. 《Python魔法大冒险》006 变量的迷雾

    小鱼和魔法师走了很久,终于来到了一个神秘的森林前.这片森林与众不同,它被一层厚厚的迷雾所包围,仿佛隐藏着无尽的秘密. 小鱼好奇地看着这片森林:"这是什么地方?" 魔法师:这是魔法森 ...

  7. Gradle安装配置教程

    一.安装前检查 检查电脑上是否安装JDK,如果没有安装,请查看JDK安装教程:点击查看 如果电脑上已经安装JDK,按Win + R键,输入cmd,然后点击确定 输入java -version,点击回车 ...

  8. AnyLabeling标定及转化成labelmaskID

    一.标定工具 在进行分割任务时,对分割工具进行预研和验证,现在AI辅助标定已经成熟,目标则是利用sam进行辅助标定.调研的三款标定工具情况如下: labelme:可以加载sam,但是在进行辅助标定后, ...

  9. Solution Set -「CF 1539」

    我是傻逼. 「CF 1539A」Contest Start Link. 答案是 \(\sum_{i=1}^{n-1}\min\{i,\lfloor\frac{t}{x}\rfloor\}\),等差数列 ...

  10. POWERBI_1分钟学会_连续上升或下降指标监控

    一:数据源 模拟数据为三款奶茶销量的日销售数据源,日期是23.8.24-23.8.31.A产品为连续7天,日环比下降,B产品为连续3天,日环比下降,C产品为连续2天,日环比下降. 二:建立基础度量值 ...