当前位置:网站首页>2022河南萌新联赛第(三)场:河南大学
2022河南萌新联赛第(三)场:河南大学
2022-07-26 17:01:00 【AC自动寄】
J-神奇数字
思路:
首先分析两个数同余的情况:a ≡ b ( mod x )
我们可知:(a - b) / x 一定为整数(即、x | (a - b) ),所以只需令 x 为 (a - b) 的因数 即可
其次考虑三个数同余的情况: a ≡ b ≡ c ( mod x )
等效于三个同余同时成立 :a ≡ b ( mod x ) && b ≡ c ( mod x ) && c ≡ a ( mod x )
可推出 ( x | (a - b) && x | (b - c) && x | (c - a) )
三个等式同时成立,即、x 为 gcd(a-b, b-c, c-a) 的因数(为最大公约数的因数,则三等式同时成立)
代码如下:
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(nullptr); cout.tie(nullptr)
#define x first
#define y second
#define int long long
using namespace std;
typedef pair<int, int> PII;
const int N = 2e5 + 10, M = 1010;
const int mod = 1e9 + 7;
int T;
int n, m, sum;
PII a[N];
void check(int a, int b, int c)
{
vector<int> v;
int x = __gcd(abs(a - b), __gcd(abs(b - c), abs(c - a)));
for(int i = 1; i <= x / i; i ++ )
{
if(x % i == 0)
{
v.push_back(i);
if(x / i != i) v.push_back(x / i);
}
}
sort(v.begin(), v.end());
for(auto it : v)
cout << it << " ";
cout << endl;
return;
}
void solve()
{
int a, b, c;
cin >> a >> b >> c;
if(a == b && b == c)
{
cout << "-1" << endl;
return;
}
else check(a, b, c);
}
signed main()
{
cin >> T;
while(T -- )
solve();
return 0;
}
边栏推荐
- The database uses PSQL and JDBC to connect remotely and disconnect automatically from time to time
- How to assemble a registry?
- Asemi rectifier bridge kbpc3510, kbpc3510 package, kbpc3510 application
- Spark unified memory partition
- Kudu design tablet
- Interview with celebrities | open source is a double-edged sword for security -- Wei Jianfan, author of the Chinese translation of cathedral and market
- 2.1.2 synchronization always fails
- 【机器学习】Mean Shift原理及代码
- Sign up now | oar hacker marathon phase III midsummer debut, waiting for you to challenge
- 【集训Day3】delete
猜你喜欢

第17周自由入侵 指针练习--输出最大值

# MySQL 七种连接方式图解

CCS TM4C123新建工程

Redisdesktopmanager removes the upgrade prompt

第16周OJ实践1 计算该日在本年中是第几天

How to set IP for layer 2 management switches
![[machine learning] principle and code of mean shift](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[machine learning] principle and code of mean shift
![[metauniverse OMI theory] analyze Web3 risk challenges and build Web3 ecological security](/img/d1/4a424d810f7a6aaccae80b4fe232c0.png)
[metauniverse OMI theory] analyze Web3 risk challenges and build Web3 ecological security

性能调优bug层出不穷?这3份文档轻松搞定JVM调优
![[Day2] cinema ticket](/img/da/a206266b94d1579a18f761fff74ef8.png)
[Day2] cinema ticket
随机推荐
(24) the top menu of blender source code analysis shows code analysis
如何组装一个注册中心?
[training Day1] spy dispatch
跨站脚本攻击(XSS)
【集训Day3】section
VS Code 格式化后 自动让函数名后有空格
Cloud rendering volume cloud [theoretical basis and implementation scheme]
JS closure simulates private variable interview questions and immediately executes function Iife
Overview of the agenda of the keynote speech of apachecon Asia, an international celebrity vs a local open source star
Zhaoqi science and technology innovation overseas high-level talent introduction platform, entrepreneurship event Roadshow
Open source kaggle cat and dog data set -- used in classic CNN classification practice
6-19漏洞利用-nsf获取目标密码文件
How to assemble a registry?
How to set IP for layer 2 management switches
Redisdesktopmanager removes the upgrade prompt
Heavy announcement! Icml2022 Awards: 15 outstanding papers, selected by Fudan University, Xiamen University and Shanghai Jiaotong University
Spark数据格式UnsafeRow
Tree DP problem
[machine learning] principle and code of mean shift
Cross Site Request Forgery (CSRF)