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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T20:25:38+00:00 2026-05-12T20:25:38+00:00

is there a fast algorithm, similar to power of 2, which can be used

  • 0

is there a fast algorithm, similar to power of 2, which can be used with 3, i.e. n%3.
Perhaps something that uses the fact that if sum of digits is divisible by three, then the number is also divisible.

This leads to a next question. What is the fast way to add digits in a number? I.e. 37 -> 3 +7 -> 10
I am looking for something that does not have conditionals as those tend to inhibit vectorization

thanks

  • 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-12T20:25:39+00:00Added an answer on May 12, 2026 at 8:25 pm

    4 % 3 == 1, so (4^k * a + b) % 3 == (a + b) % 3. You can use this fact to evaluate x%3 for a 32-bit x:

    x = (x >> 16) + (x & 0xffff);
    x = (x >> 10) + (x & 0x3ff);
    x = (x >> 6) + (x & 0x3f);
    x = (x >> 4) + (x & 0xf);
    x = (x >> 2) + (x & 0x3);
    x = (x >> 2) + (x & 0x3);
    x = (x >> 2) + (x & 0x3);
    if (x == 3) x = 0;
    

    (Untested – you might need a few more reductions.) Is this faster than your hardware can do x%3? If it is, it probably isn’t by much.

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

Sidebar

Related Questions

Is there any fast algorithm that allows to compare two files (for verification purpose)
Is there an efficient (fast) algorithm that will perform bit expansion/duplication? For example, expand
It seems that there are several really fast prime factorization algorithms around (one that
Is there a fast algorithm for finding the Largest Common Substring in two strings
Given two arrays, is there a fast algorithm for finding all elements in the
There are several ICA algorithms in use. Such as Fast-ICA algorithm, there is one
I'm looking for a fast asymmetric cypher algorithm to be used in C++ program.
Is there any fast implementation of cryptographically secure pseudorandom number generator (CSPRNG) for C#
Is there a fast/efficiency way to check if a table is empty? DECLARE @StartEndTimes
Is there a fast way to count the amount of successive null bytes starting

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.