您当前的位置: 首页 > 

MangataTS

暂无认证

  • 0浏览

    0关注

    423博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Codeforces Round #629 (Div. 3) A~C

MangataTS 发布时间:2020-03-27 21:24:00 ,浏览量:0

昨天晚上打了一场CF,由于网卡,还有英语题读题较慢,所以只AC了3道题->_->

(准确的来说AC了2道,因为最后凌晨的时候我这边网络直接崩了,连接不上codefores,就没提交成功QAQ) 好了,开始进入正题:

A:

A. Divisibility Problem
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

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).

Output

For each test case print the answer — the minimum number of moves you need to do in order to make aa divisible by bb.

Example
input
Copy
5
10 4
13 9
100 13
123 456
92 46

output
Copy
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

关注
打赏
1665836431
查看更多评论
0.0373s