Project Euler #125: Palindromic sums

  • + 1 comment

    Works fine for sample test case 0 and sample test case 34. All other cases failed. Can someone help me please? Thanks.!`

    for (int i = 0; i < T; i++) {

    for (unsigned long long j = 1;; j++)
    {
      if (j * j >= case1[i].Num)
        break;
      sum = 0;
      count = 0;
      for (int k = j;; k = k + case1[i].dif)
      {
        sum = sum + k * k;
        count++;
        if (sum >= case1[i].Num)
          break;
        sprintf(str1, "%llu", sum);
        for (p = 0, q = strlen(str1); str1[p] != '\0'; p++, q--)
        {
          str2[q - 1] = str1[p];
        }
        str2[p] = '\0';
    
        if (strcmp(str1, str2) == 0 && count >= 2)
        {
          for (unsigned long long l = 0; l < r; l++)
          {
            if (sum == sums[i])
            {
              flag = 0;
            }
          }
          if (flag)
          {
            Lsum = Lsum + sum;
            sums[r] = sum;
            r++;
          }
        }
      }
    }
    printf("%llu\n", Lsum);
    Lsum = 0;
        }
    

    }

    return 0; }