原题链接:

Problem - E1 - Codeforces

题目描述:

This is an easy version of the problem. The only difference between an easy and a hard version is the constraints on aa, bb, cc and dd.

You are given 44 positive integers aa, bb, cc, dd with a<ca<c and b<db<d. Find any pair of numbers xx and yy that satisfies the following conditions:

  • a<x≤ca<x≤c, b<y≤db<y≤d,
  • x⋅yx⋅y is divisible by a⋅ba⋅b.

Note that required xx and yy may not exist.

Input

The first line of the input contains a single integer tt (1≤t≤10(1≤t≤10), the number of test cases.

The descriptions of the test cases follow.

The only line of each test case contains four integers aa, bb, cc and dd (1≤a<c≤1051≤a<c≤105, 1≤b<d≤1051≤b<d≤105).

Output

For each test case print a pair of numbers a<x≤ca<x≤c and b<y≤db<y≤d such that x⋅yx⋅y is divisible by a⋅ba⋅b. If there are multiple answers, print any of them. If there is no such pair of numbers, then print -1 -1.

题目大意:

给定a,b,c,d,问有没有x,y满足a < x <= c, b < y <= d且x * y能被a * b整除,如果有多组答案,则输出任意一组x,y即可,如果不存在答案,则输出-1。

解题思路:

数据不大,1e5,O(n)是完全可承受的,我们可以枚举x,设e = a * b / gcd(a * b, x),则任何一个大于b且小于等于d的e的倍数都可以满足题目的需求。我们让y = (b + e) / e * e即可得到最小的大于b的e的倍数,只要他同时满足小于等于d,那么这个x和y就可以是答案。如果枚举完所有的x都找不到合适的y,即无解。

代码(CPP):

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
typedef unsigned long long ull;
const int maxn = 1e3 + 10;
const int INF = 0x3fffffff;signed main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout << fixed;cout.precision(18);int t;cin >> t;while(t--){int a, b, c, d;cin >> a >> b >> c >> d;bool flag = false;for (int x = a + 1; x <= c; x++){int e = a * b / __gcd(a * b , x);int y = (e + b) / e * e;if(y > b && y <= d){cout << x << " " << y << endl;flag = true;break;}}if(!flag)cout << "-1 -1\n";}return 0;
}

Codeforces Round #828 (Div. 3) E1. Divisible Numbers (easy version) 解题报告相关推荐

  1. Codeforces Round #828 (Div. 3) E2. Divisible Numbers (hard version)

    翻译: 这是这道题的难解版.简单版本和硬版本之间的唯一区别是对

  2. codeforces:E1. Divisible Numbers (easy version)【数论 + 复杂度计算 + 分解质因数】

    目录 题目截图 题目分析 想法1:遍历所有可能的xy(tle) 想法2:遍历可能的x(accepted) 总结 题目截图 题目分析 想法1,遍历所有kab作为xy的所有可能值,找到其所有因子,然后看看 ...

  3. E1. Divisible Numbers (easy version)(数学)

    Problem - E1 - Codeforces 题意: 这是一个简单版本的问题.简单版和困难版的唯一区别是对a.b.c和d的限制. 给你4个正整数a.b.c.d,a<c,b<d.找到任 ...

  4. Codeforces Round #560 (Div. 3)F1.F2. Microtransactions (easy version)

    题目来源: F1:https://codeforces.com/contest/1165/problem/F1 F2:https://codeforces.com/contest/1165/probl ...

  5. Codeforces Round #828 (Div. 3)-赛后总结

    Dashboard - Codeforces Round #828 (Div. 3) - Codeforces 打完比赛的晚上美滋滋的看着解出来的六道题,心想着能够加上一百多分.一觉醒来眼睁睁看着E1 ...

  6. Codeforces Round #658 (Div. 1) A2. Prefix Flip (Hard Version)

    Codeforces Round #658 (Div. 1) A2. Prefix Flip (Hard Version) 题目链接 There are two binary strings a an ...

  7. Codeforces Round #112 (Div. 2) E. Compatible Numbers sosdp

    传送门 文章目录 题意: 思路: 题意: 思路: 以下假设all=1<<22all=1<<22all=1<<22. 转化问题,对于每个aia_iai​我们都计算x= ...

  8. Codeforces Round #620 (Div. 2) F2. Animal Observation (hard version) dp + 线段树

    传送门 文章目录 题意: 思路: 题意: 比如下面这个图: 思路: 对于这个题,比较容易就能考虑到dpdpdp,设f[i][j]f[i][j]f[i][j]为到了第iii行,覆盖了[j,j+k−1][ ...

  9. Codeforces Round #617 (Div. 3) E2. String Coloring (hard version) 思维 + dp + Dilworth定理

    传送门 文章目录 题意: 思路: 题意: 让你给一个串染色,不同颜色且相邻的一对字符可以互换位置,用最少的颜色,使交换后这个字符串字典序最小. 思路: 考虑将字符串分成若干个非递减的子序列,由于其非递 ...

最新文章

  1. 2021年大数据Spark(十八):Spark Core的RDD Checkpoint
  2. CV进入三维时代!Facebook在ICCV 2021 发布两个3D模型,自监督才是终极答案?
  3. 暖风熏得游人醉,直把杭州作汴州 | 把将直角当做斜角来发车
  4. textview 垂直居中_在Textview左边或右边添加图标 ,换行不错位
  5. mysql 8.14 rpm安装_centos8 安装 mysql8
  6. SOCKET编程-时间服务器和客户端的实现
  7. How far away ?
  8. linuxl下创建mysql用户和组_Linux中用户与用户组管理
  9. 科普漫画 | 沙子如何变成芯片?
  10. 安卓从业者应该关注:Android 6.0的运行时权限
  11. Devuan Jessie beta 释出
  12. php页面添加链接,怎么给一个PHP密码访问页面加超链接
  13. 【Spring】jpa数据库表实体命名规则 Unknown column ‘user0_.create_time‘ in ‘field list‘
  14. JQuery将用户输入的数字转换为大写
  15. win7无法打开计算机共享文件夹,win7无法共享文件夹 共享文件设置不了共享怎么办?...
  16. 计算机学院陈冠华,生命科学学院2020年研究生学业奖学金(老生)获奖名单公示...
  17. java斜体_设置标签字体用粗体和斜体
  18. 全国计算机考试比省级的难吗,国考和省考考题的区别,难度差异很大吗?
  19. C++搭建集群聊天室(十四):群聊功能
  20. java 创建新的图片,底色自己设定

热门文章

  1. Espresso测试示例
  2. 如何做好PPT——画图篇
  3. 对《A Fast Parallel Algorithm for Thinning Digital Patterns》一文的理解(上)
  4. 巧妙去掉多余的安全删除硬件图标
  5. 转载-css 属性clip-path之多边形polygon小窥
  6. html5 盒子阴影效果,如何制作平滑的“box-shadow”盒子阴影动画效果
  7. 序列周期性与魔术(一)——数学里的函数周期性
  8. Html之 图像标记
  9. 工程师的终极灵魂拷问: 谷歌和FB的offer, 应该怎么选?
  10. 随机抽样java_java实现从一个群体中随机抽样一定数量样本