[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 35 KB, 468x600, Weiner's Constant.gif [View same] [iqdb] [saucenao] [google]
5091416 No.5091416 [Reply] [Original]

Hi /sci/.

I need a method to find the lowest positive integer r, such that <span class="math">10^r \equiv 1 (\textup{mod } p)[/spoiler], where p is a given prime. Brute force searching isn't fast enough here.

It's for Project Euler, Problem 26, if anybody is interested.

Thanks.

>> No.5091430
File: 66 KB, 504x703, Homohms.gif [View same] [iqdb] [saucenao] [google]
5091430

Oh dear. I meant:

I need a method to find the lowest positive integer r, such that <span class="math">10^r \equiv 1[/spoiler] (mod p), where p is a given prime.

>> No.5091450
File: 31 KB, 338x450, Oppenheimer.jpg [View same] [iqdb] [saucenao] [google]
5091450

Disguised bump:

Finding r is equivalent to finding the length of the first repunit divisible by p. But that only seems to complicate things.

>> No.5091451

Why the hell would you ever need that for 26? Do you know long division?

>> No.5091455

>>5091451
I like trying to do them more mathematically, I learn more.

>> No.5091459

>>5091451
Also, you couldn't definitely say when the decimal expansion starts repeating.

>> No.5091474

>>5091416
I'm pretty sure a recursive program is fast enough

>> No.5091492
File: 748 KB, 960x1299, Appeal Chute Hypothesis.jpg [View same] [iqdb] [saucenao] [google]
5091492

>>5091474
I have to do this for all primes less than 1000.

But on examining my program, the speed might not be the problem, but the fact that Visual Basic can't handle numbers above 10^19, and r ends up higher than 19 for a lot of the primes.

So, a method of computing 10^r (mod p), without computing 10^r, would also be incredibly useful.

>> No.5091498

Assuming p > 10, then 10^(p-1) = 1 mod p, by fermat's little theorem. By lagranges theorem, we have that r divides p-1.

So, for example, if p = 1657, then you only need test the divisors of 1656. Try them starting with the smallest divisors.

>> No.5091509

>>5091498
10^r (mod p) = 10 (mod p) * 10^(r-1) (mod p)

Basically, you don't need to do every single power before applying the modulus. You can mod by p at every step.

>> No.5091524

>>5091455
You learn more, but what? Asking 4chan for the answer? Terrible.

>> No.5091521 [DELETED] 

Z/pZ is a group under multiplication, and it has p elements.
Lagrange tells us that, if there is a subgroup in Z/pZ, then its size must be a divisor of p.
But p is a prime, so its only divisors are 1 and p.
<10> generates a group, in the form of 10^n, so its size must be either 1 or p.
From that we can get that 10 ^ (size) is 1.
It can't be that size = 1, or else 10^1 = 1, which it doesn't make sense.
So it must be that 10^p = 1.
Thus, the number you're looking for is p.

Note that this doesn't work for p = 2 or p = 5, as 10 mod p = 0, and 0 ^ anything will never produce 1.

>> No.5091531 [DELETED] 

>>5091521
Wrong. Z/pZ under multiplication has p-1 elements, not p elements.

>> No.5091588
File: 2.96 MB, 390x400, Jupiter Surface.gif [View same] [iqdb] [saucenao] [google]
5091588

>>5091498
>>5091509
Thank you, this seems very helpful. Modular arithmetic is lovely.

>>5091524
I'm not asking for the answer, I'm asking for a possible way forward, and somebody has helped, and I now know more than I did before.

>> No.5091605
File: 30 KB, 464x578, Discrete mathematics.jpg [View same] [iqdb] [saucenao] [google]
5091605

Here's what I started studying this month.

>> No.5091622

Hurray, I got the answer.

>10^r (mod p) = 10 (mod p) * 10^(r-1) (mod p)

Was what helped.

Time to laugh at other people's brute force algorithms in the forum.