Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:23:12+00:00 2026-05-22T12:23:12+00:00

I was solving this problem6 , I dont even know the answer but, when

  • 0

I was solving this problem6, I dont even know the answer but, when I finished I think that I will get Ok, but my answers fails, 7910956276398901303 this is my answer 1303, can you help me with this error, I dont understand what is wrong my logic , code??, Its just a simple power function

Corrected

this is the correct code

import java.math.BigDecimal;

public class Problema6 {

static BigDecimal sum = BigDecimal.valueOf(0);
static BigDecimal num = BigDecimal.valueOf(0);

public static void main(String args[]) {
    int n = 2;

    for (int i = 1; i <= 15; i++) {
        sum = sum.add(power(i, n));
        n++;
    }
    System.out.println(sum);

    String number = sum.toString();

    System.out.println(number.substring(number.length() - 4, number.length()));

}

public static BigDecimal power(int x, int y) {

    num = BigDecimal.valueOf(x).pow(y).add(BigDecimal.valueOf(y).pow(x));

    return num;
}

}

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:23:12+00:00Added an answer on May 22, 2026 at 12:23 pm

    I think the problem is with using Math.pow(...). Switch to BigDecimal.pow(...) to avoid overflows

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am solving this task Problem28 , I think that its a easy
I took a look at this answer and it goes in part to solving
<hyperbole> Whoever answers this question can claim credit for solving the world's most challenging
I know there is a lot of information in the Internet about solving this
I need some help in solving this problem. We have a large amount of
I have a custom NSView which contains a subview—for the purposes of solving this
This is my first effort on solving the exercise. I gotta say, I'm kind
This is related to my previous question I'm solving UVA's Edit Step Ladders and
I'm solving UVA's Edit Step Ladders on an uva sub-site named programming-challenges.com, but since
This is probably a common Objective-C question reported by Java coders, but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.