[HDU] [1229] Still A+B

Problem Description

Loading...

Problem Analysis

A very simple problem
Mainly about determining whether the last few digits of the numbers are the same

The modulo operation is used here
So we need to take the remainder modulo 1 followed by k zeros

On a sudden whim, I wrote a recursive function to compute the number formed by 1 followed by k zeros

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
int fx(int m) {
	if(m==0)
		return 1;
	else
		return 10*fx(m-1);
}
int main() {
	int a,b,k,t;
	while(scanf("%d %d %d",&a,&b,&k),a!=0||b!=0) {
		t=fx(k);
		if(a%t!=b%t)
			printf("%d\n",a+b);
		else
			printf("-1\n");
	}
	return 0;
}

Problem address: 【HDU】[1229]Still A+B

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...