1017. A divided by B (20) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Chen, Yue
The subject requires a A/b, where A is a positive integer that does not exceed 1000 bits, and B is a 1-bit positive integer. You need to output the quotient Q and the remainder r so that a = B * Q + R is set up.
Input format:
The input is given a and B in 1 rows, and the middle is separated by 1 spaces.
Output format:
In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.
Input Sample:
123456789050987654321 7
Sample output:
17636684150141093474 3
Note: A has only one digit when the first bit of a is less than B.
1 //1017.cpp: Defines the entry point of the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <string>7#include <typeinfo>8 9 using namespacestd;Ten One intMain () A { - stringa,q; - intB, R; the -CIN >> A >>B; - - intSize =a.size (); + - if(Size = =1) +cout << (a[0] - -)/B <<" "<< (a[0] - -)% B <<Endl; A Else at { - if((a[0]) < B + -) - { -Q.push_back ((((a[0] - -) *Ten+ a[1] - -)/B) + -); -R = ((a[0] - -) *Ten+ a[1] - -) %B; - } in Else - { toQ.push_back ((a[0] - -)/b + -); +R = (a[0] - -) %B; - theQ.push_back (((R *Ten+ a[1] - -)/B) + -); *R = (R *Ten+ a[1] - -) %B; $ }Panax Notoginseng - for(inti =2; i < size; ++i) the { +Q.push_back (((R *Ten+ A[i]- -)/B) + -); AR = (R *Ten+ A[i]- -) %B; the } + -cout << Q <<" "<< R <<Endl; $ } $ - return 0; -}
PAT class 1017 A divided by B (c)