Codeforces Round #786 (Div. 3) A. Number Transformation
Posted on 2022-10-12 21:11 zeitspeed 阅读(13) 评论(0) 编辑 收藏 举报time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
You are given two integers x and y. You want to choose two strictly positive (greater than zero) integers a and b, and then apply the following operation to x exactly a times: replace x with b⋅x.
You want to find two positive integers a and b such that x becomes equal to y after this process. If there are multiple possible pairs, you can choose any of them. If there is no such pair, report it.
For example:
if x=3 and y=75, you may choose a=2 and b=5, so that x becomes equal to 3⋅5⋅5=75;
if x=100 and y=100, you may choose a=3 and b=1, so that x becomes equal to 100⋅1⋅1⋅1=100;
if x=42 and y=13, there is no answer since you cannot decrease x with the given operations.
Input
The first line contains one integer t (1≤t≤104) — the number of test cases.
Each test case consists of one line containing two integers x and y (1≤x,y≤100).
Output
If it is possible to choose a pair of positive integers a and b so that x becomes y after the aforementioned process, print these two integers. The integers you print should be not less than 1 and not greater than 109 (it can be shown that if the answer exists, there is a pair of integers a and b meeting these constraints). If there are multiple such pairs, print any of them.
If it is impossible to choose a pair of integers a and b so that x becomes y, print the integer 0 twice.
Example
inputCopy
3
3 75
100 100
42 13
outputCopy
2 5
3 1
0 0
#include<iostream>
using namespace std;
int main(void) {
int n;
scanf("%d", &n);
int x, y;
for (int i = 0; i < n; i++) {
scanf("%d %d", &x, &y);
if (y % x != 0) {
printf("0 0\n");
}
else {
printf("1 %d\n", y / x);
}
}
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现