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
This problem to find long time fault, in this machine debugging multiple answers are correct, but after submission is not, finally found that temp did not assign the initial value of 0. Pay more attention to it later.
1#include <stdio.h>2#include <string.h>3#include <math.h>4#include <stdlib.h>5 intMain () {6 Chara[ -];7scanf"%s", a);8 intb;9scanf"%d",&b);Ten intn =strlen (a); One inttemp=0; A intFlag =0; - for(intI=0; i<n;i++){ -temp = (a[i]-'0') +temp*Ten; the if(temp>=b) { -printf"%d", temp/b); -Flag =1; - } + Else if(flag) { -printf"0"); + } Atemp = temp%b; at } - if(flag==0) -printf"0"); -printf"%d", temp); -}
PAT 1017. A divided by B (20)