昨天晚上打了一场CF,由于网卡,还有英语题读题较慢,所以只AC了3道题->_->
(准确的来说AC了2道,因为最后凌晨的时候我这边网络直接崩了,连接不上codefores,就没提交成功QAQ) 好了,开始进入正题:
A:
You are given two positive integers aa and bb. In one move you can increase aa by 11 (replace aa with a+1a+1). Your task is to find the minimum number of moves you need to do in order to make aa divisible by bb. It is possible, that you have to make 00 moves, as aa is already divisible by bb. You have to answer tt independent test cases.
The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
The only line of the test case contains two integers aa and bb (1≤a,b≤1091≤a,b≤109).
For each test case print the answer — the minimum number of moves you need to do in order to make aa divisible by bb.
5
10 4
13 9
100 13
123 456
92 46
2
5
4
333
0
这个题的大意就是a被b整除的最小的位移是多少,就是一道数学签到题,不过也有需要注意的地方。
注: 1> a不能--,只能++;
2> 当a==b时,直接输出0就行
3> a可能小于b
总之,分类讨论就行:,所以可以得到如下代码
1 #include
2 int main(void)
3 {
4 int t,a,b;
5 scanf("%d",&t);
6 while(t--)
7 {
8 scanf("%d %d",&a,&b);
9 if(a%b==0)
10 printf("0\n");
11 else if(a>b)
12 printf("%d\n",b-a%b);
13 else if(a2n>2) let's write down all the strings of length nn which contain n−2n−2 letters 'a' and two letters 'b' in lexicographical (alphabetical) order.
Recall that the string ss of length nn is lexicographically less than string tt of length nn, if there exists such ii (1≤i≤n1≤i≤n), that si
关注
打赏
最近更新
- 深拷贝和浅拷贝的区别(重点)
- 【Vue】走进Vue框架世界
- 【云服务器】项目部署—搭建网站—vue电商后台管理系统
- 【React介绍】 一文带你深入React
- 【React】React组件实例的三大属性之state,props,refs(你学废了吗)
- 【脚手架VueCLI】从零开始,创建一个VUE项目
- 【React】深入理解React组件生命周期----图文详解(含代码)
- 【React】DOM的Diffing算法是什么?以及DOM中key的作用----经典面试题
- 【React】1_使用React脚手架创建项目步骤--------详解(含项目结构说明)
- 【React】2_如何使用react脚手架写一个简单的页面?


微信扫码登录