当前位置:网站首页>2022河南萌新联赛第(三)场:河南大学 J - 神奇数字
2022河南萌新联赛第(三)场:河南大学 J - 神奇数字
2022-07-26 04:29:00 【WA_自动机】
J - 神奇数字
解法:如果三个数相等, 对任何数取余结果都相同, 输出 − 1 −1 −1。如果不想等, 想到任何数都可以写成 x × y + w x×y +w x×y+w, 作 a − b = ( x 1 − x 2 ) × y a−b = (x1 −x2)×y a−b=(x1−x2)×y, 此 时 a , b a, b a,b 对 x 1 − x 2 x1 − x2 x1−x2, y 取余结果相同, 如果是 a , b , c a, b, c a,b,c 则取 g c d ( a b s ( a − b ) , a b s ( b − c ) , a b s ( a − c ) ) gcd(abs(a − b), abs(b − c), abs(a − c)) gcd(abs(a−b),abs(b−c),abs(a−c)) 然后输出所有的质因子即可。
#include<bits/stdc++.h>
using namespace std;
int main()
{
int T;cin>>T;
while(T--)
{
int a,b,c;cin>>a>>b>>c;
if(a==b&&a==c) cout<<"-1"<<endl;
else
{
int d1=abs(a-b),d2=abs(b-c);
int t=__gcd(d1,d2);
set<int> s;
for(int i=1;i*i<=t;i++)
if(t%i==0)
{
s.insert(i);
if(i*i!=t) s.insert(t/i);
}
for(auto &p:s)
cout<<p<<" ";
cout<<endl;
}
}
return 0;
}
边栏推荐
- 1. Mx6u-alpha development board (main frequency and clock configuration experiment)
- 生活相关——减少期待,更快乐
- makefile知识再整理(超详细)
- Low cost, fast and efficient construction of digital collection app and H5 system, professional development of scallop technology is more assured!
- How to write the summary? (including 7 easily ignored precautions and a summary of common sentence patterns in 80% of review articles)
- 【学习笔记】AGC041
- Sangi diagram of machine learning (for user behavior analysis)
- Network Security Learning - permission promotion 2
- Compiled by egg serialize TS
- Acwing刷题
猜你喜欢
随机推荐
Keil V5 installation and use
二、国际知名项目-HelloWorld
人脸数据库收集总结
解析Steam教育的课程设计测评体系
FFmpeg 视频编码
Acwing brush questions
UE4 获取玩家控制权的两种方式
Recommendation | DBT skills training manual: baby, you are the reason why you live
这种是我的vs没连上数据库吗
MapReduce中分区数与ReduceTask个数关系比较
数组排序2
数据仓库
SEGGER Embedded Studio找不到xxx.c或者xxx.h文件
Spark Structured Streaming HelloWorld
idea插件离线安装(持续更新)
How to choose the key words of the thesis?
How does win11 22h2 skip networking and Microsoft account login?
UE4 多个角色控制权的切换
MATLAB绘图
香甜的黄油









