Number of Solutions for Math Equations: 3x + y = 5702


You are asked to find the number of order pairs (x, y) such that, tex_b7cc060525bec71024df0093ebe1a680 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math and x, y are natural numbers which also satisfy tex_22075aa62cb55d8c4e3bd977a8c3a362 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math .

Mathematics

This shouldn’t be too complex. If we let tex_566e5696cb7d6eb3ff0daba53948bcb1 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math where tex_3aad216e845b26c24374c95bed8d5cc6 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math .

If we mod 3, we then have this:
tex_697322ce2975bfba8baf991395d837b4 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math
tex_bed10b7788e29e4e60ccf2dc248a6b24 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math
tex_d56f218cfa6800db90fd04dc48c20b8a Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math .

So, all the solutions are tex_26e7514a70366a1704ab4418faaf26e1 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math where where tex_3aad216e845b26c24374c95bed8d5cc6 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math .

Since tex_22075aa62cb55d8c4e3bd977a8c3a362 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math so we have tex_9226f508be6f6cd13da2ade215502608 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math ,
tex_15a2ae52a58f8c89d00b1f89e315635a Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math
tex_a19a8fda2383bfa15dde9d8328389030 Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math .

We have 51 solutions because k can be from 0 to 50 inclusive.

tex_cc9e84475d33870e9626833219b7e65b Number of Solutions for Math Equations:  3x + y = 5702 c / c++ code coding exercise math

Bruteforce

If you don’t like maths, then write a small piece of C++ code that verifies this via bruteforce all possibilities within the conditions:

1
2
3
4
5
6
7
int sum = 0;
for (int x = 1; x <= 2002; x ++) {
    for (int y = 1; y <= 2003 - x; y ++) {
        if (3 * x + y == 5702) sum ++;
    }
}
cout << sum << endl;
int sum = 0;
for (int x = 1; x <= 2002; x ++) {
    for (int y = 1; y <= 2003 - x; y ++) {
        if (3 * x + y == 5702) sum ++;
    }
}
cout << sum << endl;

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
662 words
Last Post: How to Remove all elements of val From a Linked List?
Next Post: ScriptUnit - VBScript/JScript Unit Tests Runner

The Permanent URL is: Number of Solutions for Math Equations: 3x + y = 5702

Leave a Reply