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 5927953
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:14:16+00:00 2026-05-22T14:14:16+00:00

I have big numbers K , C[1] , C[2] , C[3] etc. and I

  • 0

I have big numbers K, C[1], C[2], C[3] etc. and I have to calculate b:

b = C[1]*C[2]+C[3]*C[4]+... (mod K)

Now I calculate the full sum and then make something like

b = SUM % K.

But this is not work when SUM becomes bigger then unsigned long limit, so I have to use something like

b = (C[1]*C[2] %K + C[3]*C[4] %K ) %K

But this is time-consuming. I’ve tried to use unsigned long long except unsigned long and this is time-consuming too. Is there any better way?

UPD:

  C = (unsigned long long int *) malloc(N*sizeof(unsigned long long int));
  unsigned long int i, j, l;
  C[0] = 1;
  for (i=1; i<=N; i++) {
    C[i] = 0;
    l = (unsigned long int) i/2;
    for (j=0; j<l; j++) {
      C[i] += C[j]*C[i-j-1];
      C[i] = C[i] % K;
    }
    C[i] = C[i]*2;
    C[i] = C[i] % K;
    if (i - l*2 == 1) {
      C[i] += C[l]*C[l];
    }
    C[i] = C[i] % K;
  }
  • 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-22T14:14:16+00:00Added an answer on May 22, 2026 at 2:14 pm

    If you can factor K into pairwise relatively prime numbers K1,…,Kn then you can do the computation for each Ki and combine the results into a result for K by using the Chinese remainder theorem. This is usually much faster, especially if the Ki fit into a machine word.

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

Sidebar

Related Questions

so I have this HTML table with a bunch of big numbers in it
Does emacs have support for big numbers that don't fit in integers? If it
I have big system that make my system crash hard. When I boot up,
I will be working on a big Assembly project but am now just starting
I'm a big fan of log4net , but recently, some (in my department) have
I have a rather big number of source files that I need parse and
I have big issue with url-rewriting for IIS 7.0. I've written simple module for
I have big URL list, which I have to download in parallel and check
I have big trouble with file uploads with php. My own tests are successful
I have big problem when I am trying to deploy my app over clickonce.

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.