Perfect Squares
InterviewTime limit2sMemory limit128 MB
Given two numbers M and N up to 10000, sum all perfect squares in that inclusive range and print the smallest one, or -1 if none exist.
- Level
Easy2 of 10
- Topics
- Math, Brute force, Implementation
- Solved
- No attempts yet
Problem
Given two natural numbers M and N, find every perfect square between M and N, inclusive. Print the sum of those perfect squares and the smallest one. For example, if M=60 and N=100, the perfect squares in the range are 64, 81, and 100, so their sum is 245 and the smallest is 64.
Input
The first line contains M, and the second line contains N. M and N are natural numbers not greater than 10000, and M is less than or equal to N.
Output
Find all perfect squares between M and N, inclusive. If at least one exists, print their sum on the first line and the smallest one on the second line. If none exists, print -1 on the first line.