Codeforces Round #653 (Div. 3) 解题报告

本文介绍了Codeforces Round #653 (Div. 3)的比赛题目,包括ARequired Remainder、Multiply by 2, divide by 6、Move Brackets、Zero Remainder Array和Reading Books (easy version)五道题目。针对每道题目,详细阐述了题目的意思、解题思路,并提供了AC代码。" 136566462,1291382,大型语言模型在社交媒体机器人检测中的机遇与挑战,"['自然语言处理', '人工智能', '机器学习', '社交媒体分析', '安全与隐私']
摘要由CSDN通过智能技术生成

Codeforces Round #653 (Div. 3)

A.Required Remainder

题目大意

给你x,y,n,问你最大的k(1 <= k <= n)满足k mod x = y是多少

解题思路

k = x * m + y <= n
m <= (n - y) / x
那么max(k) = [(n - y) / x] * x + y

AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int main() {
   
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	while (T--) {
   
		ll x, y, n;
		cin >> x >> y >> n;
		cout <<(n - y) / x * x + y << '\n';
	}
	return 0;
}

B.Multiply by 2, divide by 6

题目大意

给你一个n,每次你可以将他乘以2或者除以6(如果n % 6 == 0),问你n到达1的最少次数是多少,如果无法到达,输出-1

解题思路

n * 6 -x * 2y = 1
n = 3x * 2x-y
num = x + y = 2 * x - (x - y)
所以将n分解为x个3相乘和x - y个2相乘即可
无法分解或者出现x > x - y表示num = -1

AC代码

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
int main() {
   
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
   
		int n;
		cin >> n;
		int x = 0, xy = 0;
		while (n % 3 == 0) {
   
			++x;
			n /= 3;
		}
		while (n % 2 == 0)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值