[LightOJ] [1116] Ekka Dokka

Problem Description

Loading...

Problem Analysis

The problem asks us to
read W from the input
and then print two numbers N and M
where N is odd, M is even, and M must be as small as possible

From the statement and some math, we know
an odd number always prints “Impossible”
for an even number
we can simply brute-force
and then check each candidate

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include<stdio.h>
int main() {
	int T;
	int i;
	long long W,j,k;
	scanf("%d",&T);
	for(i=1; i<=T; i++) {
		scanf("%lld",&W);
		printf("Case %d: ",i);
		if(W&1)
			printf("Impossible\n");
		else {
			for(j=2; j<=W; j+=2) {
				if(W%j==0)
					if((W/j)&1) {
						k=W/j;
						printf("%lld %lld\n",k,j);
						break;
					}
			}
		}
	}
	return 0;
}

Problem link: [Light] [1116] Ekka Dokka

Loading...