Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть Divisibility Problem from Codeforces

  • markbirds
  • 2020-04-02
  • 223
Divisibility Problem from Codeforces
  • ok logo

Скачать Divisibility Problem from Codeforces бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно Divisibility Problem from Codeforces или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку Divisibility Problem from Codeforces бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео Divisibility Problem from Codeforces

"Angle Brackets are not allowed in description"
less than symbol was converted to #
greater than symbol was converted to $

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 a and b. In one move you can increase a by 1 (replace a with a+1). Your
task is to find the minimum number of moves you need to do in order to make a divisible by b. It is possible,

that you have to make 0 moves, as a is already divisible by b. You have to answer t independent test cases.

Input

The first line of the input contains one integer t (1#=t#=104) — the number of test cases. Then t test cases

follow.

The only line of the test case contains two integers a and b (1#=a,b#=109).

Output

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

by b.

Example

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

output
2
5
4
333
0

Source Code:

First Attempt(Time Limit Exceeded):

#include#iostream$
using namespace std;

int moves(int a,int b){
int counter=0;
while(true){
if(a%b==0){
return counter;
}
counter++;
a++;
}
}

int main(){
int t,a,b;
cin$$t;
for(int i=0;i#t;i++){
cin$$a$$b;
cout##moves(a,b)##endl;
}
return 0;
}


Second Attempt(Accepted):

#include#iostream$
using namespace std;

int moves(int a,int b){
if(a%b==0){
return 0;
}
return b-(a%b);
}

int main(){
int t,a,b;
cin$$t;
for(int i=0;i#t;i++){
cin$$a$$b;
cout##moves(a,b)##endl;
}
return 0;
}

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]