[LightOJ] [1078] Integer Divisibility

Problem Description

Loading...

Problem Analysis

The idea of this problem is for example, given the input 3 1 it asks for the minimum count of digits 1 whose number is divisible by 3 e.g. 111 is divisible by 3 so output 3 likewise for 7 3 333333 is divisible by 7 so output 6

Using the congruence theorem the AC code is as follows

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<stdio.h>
int main() {
	int T,n,m,k,r;
	int i;
	scanf("%d",&T);
	for(i=1; i<=T; i++) {
		scanf("%d %d",&n,&m);
		r=m%n;
		k=1;
		while(r) {
			r=(r*10+m)%n;
			k++;
		}
		printf("Case %d: %d\n",i,k);
	}
	return 0;
}

Problem link: 【Light】[1078]Integer Divisibility

Loading...