Codeforces Round #629 (Div. 3) A~C
昨天晚上打了一场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<stdio.h> 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(a<b) 14 printf("%d\n",b-a); 15 } 16 return 0; 17 }
好了,我们来看第二道题吧;