Problem 52834. Easy Sequences 32: Almost Pythagorean Triples
Solution Stats
Problem Comments
-
9 Comments
Like David Hill, my answer matches the test cases where n<=10, but not for larger ones. I've been driving myself batty the last couple of days trying to figure out where I went wrong. Then I realized that the test cases have it wrong. I can't prove I'm right, but I can prove them wrong:
Consider the defining condition: c² = a² + b² - 1.
Rearrange: c² - a² - b² = -1.
Modulo 2: c² - a² - b² ≡ 1 (mod2).
As squaring and negation preserve parity (value mod 2),
c + a + b ≡ 1 (mod2)
And all of the answers in the test cases are even for n>10.
My "double" solution matches my int64 solution up through 1000 but not 10,000, which is what I expected as flintmax is ~9e15.. My double solution (generates even perimeters for 10k+) is size 59, my int64 is 63.
I didn't run calculateSize() before trying to figure out what was up, but what I learned through that definitely shaved some points. The largest single value test case(~12e5) runs on my laptop in just under 200ms, and should run in O(n) time and constant memory. It will start overflowing when n hits about 45e5. uint64 will take it to about 9e6.
@Ramon Villamangca, there's definitely an issue with the larger test cases in this problem. From the definition and tracking parity, the perimeter of an APT MUST be odd.
Solution Comments
Show commentsGroup

Easy Sequences Volume V: Fibonacci Obsession
- 10 Problems
- 1 Finishers
- Cricket - Sort Batters by Distance Run
- Cricket - Average Partnership Contribution
- Cricket - How Much More to Beat Bradman?
- Cricket - Career Batting Statistics
- Cricket - Career Bowling Statistics
- Cricket - Represent Average in "Dulkars" and "Ses"
- Cricket - Peak Batting Average
- Cricket - Report the Result (Part I: Limited Overs)
- Cricket - Most Frequent Bowler-Batter Wicket Combinations
- Cricket - You Miss, I Hit (Rank Bowlers by Proportion of Bowled and LBW Wickets)
- Cricket - Report the Result (Part II: Test Matches)
- Cricket - Is It LBW?
Problem Recent Solvers4
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!