Codeforces: A. System of Equations


The problem is from codeforces: http://www.codeforces.com/problemset/problem/214/A

214A Codeforces: A. System of Equations algorithms brute force implementation math

Simple as that, the brute-force can pass the tests. The given ranges for n and m are acceptable for the simple brute-force algorithm. tex_8fb1f5024a605dc7737c61a8a376e067 Codeforces: A. System of Equations algorithms brute force implementation math is straightforward i.e. two for-loops for a and b ranging from 0 to 1000. Since both numbers are non-negative, only the numbers up to tex_68206d916dd6d84be5f480bd6e7e038f Codeforces: A. System of Equations algorithms brute force implementation math and tex_50162a1fdd6085bd0975a7429b764e57 Codeforces: A. System of Equations algorithms brute force implementation math need to be checked. Also, this can be simplified to tex_caa5d58969fcc95bcd6477b6782501fa Codeforces: A. System of Equations algorithms brute force implementation math via checking either a or b, and based on the other equation, computing directly the other value. The following Python code illustrates this.

#!/usr/bin/env python
# https://helloacm.com

n, m = map(int, raw_input().split(' '))

x = 0
for a in xrange(0, int(n ** 0.5) + 1):
    b = n - a * a
    if b >= 0 and a + b * b == m:
        x += 1

print x

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
362 words
Last Post: How Many Zeros at the end of 1024!?
Next Post: A Javascript PC Emulator

The Permanent URL is: Codeforces: A. System of Equations

Leave a Reply