PAT class 1017 A divided by B (c)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.