The palindromic number 595 is interesting because it can be written as the sum o
ID: 3770571 • Letter: T
Question
The palindromic number 595 is interesting because it can be written as the sum of consecutive squares: 62 + 72 + 82 + 92 + 102 + 112 + 122. There are exactly eleven palindromes below one-thousand that can be written as consecutive square sums, and the sum of these palindromes is 4164. Note that 1 = 02 + 12 has not been included as this problem is concerned with the squares of positive integers. Find the sum of all the numbers less than 108 that are both palindromic and can be written as the sum of consecutive squares. i want java program for that
Explanation / Answer
Hi,
Find below code:
class palindro{
public static void main(String hg[]){
int maxnu = 100000000;
double sqrtLimit = Math.Sqrt(maxnu);
long sum = 0;
SortedSet list = new SortedSet();
for (int i = 1; i <= sqrtLimit; i++) {
int number = i*i;
for (int j = i + 1; j <= sqrtLimit; j++) {
number += j * j;
if (number > maxnu) break;
if (IsPalindrome(number) && !list.Contains(number) ) {
sum += number;
list.Add(number);
}
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.