Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to devise a number crunching algorithm

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 :(

like image 991
Ravi Gupta Avatar asked Mar 11 '10 10:03

Ravi Gupta


People also ask

What is number crunching algorithm?

The term “number crunching” describes the act of processing numerical data. It generally refers to taking large amounts of related numerical data and organizing it into a more useful format. That organizing often includes running calculations and arranging data in charts, graphs and other visualizations.

What is number crunching in business?

number cruncher | Business Englishsomeone whose job involves working with numbers and doing calculations: The City's number crunchers estimated that the high-street retailer grew by only 0.5% in the last quarter.


1 Answers

Multiply modulo 10^6. See this Lua code.

local x=1
for i=1,100000 do
        x=(x*7) % 1e6
        if x==823543 then print(i) end
end
like image 179
lhf Avatar answered Oct 11 '22 12:10

lhf