- #1

CRGreathouse

Science Advisor

Homework Helper

- 2,820

- 0

Code:

```
power = 2;
exp = 1;
while (power != n) {
power = (2 * power) % p; // actually coded as an addition and conditional subtract
if (power == 1)
return "No solution";
exp += 1;
}
return exp;
```

Calculating the order of 2 mod p won't help -- unless it cost less than a comparison at each step, I guess. Thoughts?