Need to devise a number crunching algorithm

Posted by Ravi Gupta on Stack Overflow See other posts from Stack Overflow or by Ravi Gupta
Published on 2010-03-11T10:37:46Z Indexed on 2010/03/11 20:24 UTC
Read the original article Hit count: 326

Filed under:
|

I stumbled upon this question:

7 power 7 is 823543. Which higher power of 7 ends with 823543 ?

How should I go about it ? The one I came up with is very slow, it keeps on multiplying by 7 and checks last 6 digits of the result for a match.

I tried with Lou's code:

int x=1;
    for (int i=3;i<=100000000;i=i+4){
            x=(x*7)%1000000;
            System.out.println("i="+ i+" x= "+x);
            if (x==823543){
                System.out.println("Ans "+i);}
            }

And CPU sounds like a pressure cooker but couldn't get the answer :(

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about number-crunching