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

  • Home
  • SEARCH
  • 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 543185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:31:30+00:00 2026-05-13T10:31:30+00:00

I am have difficulties solving this problem: For a positive number n, define C(n)

  • 0

I am have difficulties solving this problem:

For a positive number n, define C(n)
as the number of the integers x, for
which 1 < x < n and x^3 = 1 mod n.

When n=91, there are 8 possible values
for x, namely : 9, 16, 22, 29, 53, 74,
79, 81. Thus, C(91)=8.

Find the sum of the positive numbers
n <= 10^11 for which C(n) = 242.

My Code:

double intCount2 = 91;
double intHolder = 0;

for (int i = 0; i <= intCount2; i++)
{
    if ((Math.Pow(i, 3) - 1) % intCount2 == 0)
    {
        if ((Math.Pow(i, 3) - 1) != 0)
        {
            Console.WriteLine(i);
            intHolder += i;
        }
    }
}
Console.WriteLine("Answer = " + intHolder);
Console.ReadLine();

This works for 91 but when I put in any large number with a lot of 0’s, it gives me a lot of answers I know are false. I think this is because it is so close to 0 that it just rounds to 0. Is there any way to see if something is precisely 0? Or is my logic wrong?

I know I need some optimization to get this to provide a timely answer but I am just trying to get it to produce correct answers.

  • 1 1 Answer
  • 0 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-13T10:31:30+00:00Added an answer on May 13, 2026 at 10:31 am

    Let me generalize your questions to two questions:

    1) What specifically is wrong with this program?

    2) How do I figure out where a problem is in a program?

    Others have already answered the first part, but to sum up:

    Problem #1: Math.Pow uses double-precision floating point numbers, which are only accurate to about 15 decimal places. They are unsuitable for doing problems that require perfect accuracy involving large integers. If you try to compute, say, 1000000000000000000 – 1, in doubles, you’ll get 1000000000000000000, which is an accurate answer to 15 decimal places; that’s all we guarantee. If you need a perfectly accurate answer for working on large numbers, use longs for results less than about 10 billion billion, or the large integer mathematics class in System.Numerics that will ship with the next version of the framework.

    Problem #2: There are far more efficient ways to compute modular exponents that do not involve generating huge numbers; use them.

    However, what we’ve got here is a “give a man a fish” situation. What would be better is to teach you how to fish; learn how to debug a program using the debugger.

    If I had to debug this program the first thing I would do is rewrite it so that every step along the way was stored in a local variable:

    double intCount2 = 91; 
    double intHolder = 0; 
    
    for (int i = 0; i <= intCount2; i++) 
    { 
        double cube = Math.Pow(i, 3) - 1;
        double remainder = cube % intCount2;
        if (remainder == 0) 
        { 
            if (cube != 0) 
            { 
                Console.WriteLine(i); 
                intHolder += i; 
            } 
        } 
    } 
    

    Now step through it in the debugger with an example where you know the answer is wrong, and look for places where your assumptions are violated. If you do so, you’ll quickly discover that 1000000 cubed minus 1 is not 99999999999999999, but rather 1000000000000000000.

    So that’s advice #1: write the code so that it is easy to step through in the debugger, and examine every step looking for the one that seems wrong.

    Advice #2: Pay attention to quiet nagging doubts. When something looks dodgy or there’s a bit you don’t understand, investigate it until you do understand it.

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

Sidebar

Ask A Question

Stats

  • Questions 295k
  • Answers 295k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer event.target might help. Another workaround is to have the three… May 13, 2026 at 6:57 pm
  • Editorial Team
    Editorial Team added an answer The schema.xml was malformed as I had copied additional text… May 13, 2026 at 6:57 pm
  • Editorial Team
    Editorial Team added an answer Yes, you should be fine since B is created in… May 13, 2026 at 6:57 pm

Related Questions

I'm working with a legacy WebLogic application that contains a web-service application and a
The design for the website I am working on calls for a custom image
I am facing difficulties to make my own Eclipse Intro Page ( as shown
I am having difficulties testing window.setInterval function in my Javascript file. Below is the
I am having difficulties figuring this out. I can see I am posting XML

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.