[HDU] [2092] Integer Solutions cpp

Problem Description

Loading...

Problem Analysis

This one kept timing out before
Then, after a senior classmate reminded me, I came up with this way of checking

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#include<stdio.h>
int main() {
	int i,j,n,m;
	int x;
	while(scanf("%d %d",&n,&m),n!=0||m!=0) {
		for(i=-100,x=0; i<100; i++) {
			if((n-i)*i==m) {
				x=1;
				break;
			}
		}
		if(x==1)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}
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...