7 kyu

GCD sum

1,294 of 3,279KenKamau

Description:

Given the sum and gcd of two numbers, return those two numbers in ascending order. If the numbers do not exist, return -1, (or NULL in C, tuple (-1,-1) in C#, pair (-1,-1) in C++,None in Rust, array {-1,-1} in Java and Golang).

For example: 
Given sum = 12 and gcd = 4...

solve(12,4) = [4,8]. The two numbers 4 and 8 sum to 12 and have a gcd of 4.

solve(12,5) = -1. No two numbers exist that sum to 12 and have gcd of 5.

solve(10,2) = [2,8]. Note that [4,6] is also a possibility but we pick the one with the lower first element: 2 < 4, so we take [2,8].

More examples in test cases.

Good luck!

Fundamentals

Stats:

CreatedNov 18, 2019
PublishedNov 18, 2019
Warriors Trained5644
Total Skips239
Total Code Submissions8054
Total Times Completed3279
JavaScript Completions1294
Python Completions1038
Ruby Completions111
Haskell Completions67
C Completions106
Clojure Completions27
C# Completions157
C++ Completions213
Java Completions280
Go Completions137
Rust Completions82
Total Stars69
% of votes with a positive feedback rating89% of 694
Total "Very Satisfied" Votes575
Total "Somewhat Satisfied" Votes85
Total "Not Satisfied" Votes34
Total Rank Assessments14
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • KenKamau Avatar
  • imjasonmiller Avatar
  • rowcased Avatar
  • hobovsky Avatar
  • username0 Avatar
  • user8436785 Avatar
Ad