KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
For 1 <= N <= 1000000000 , I need to compute 2 N mod 1000000007 , and it must be really fast! My current approach is: ull power_of_2_mod(ull n) { ull result = 1; if (n <= 63) { result <<= n; result = result % 1000000007; } else { ull one = 1; one <<= 63; while (n > 63) { result = ((result % 1000000007) * (one % 1000000007)) % 1000000007; n -= 63; } for (int i = 1; i <= n; ++i) { result = (result * 2) % 1000000007; } } return result; } but it doesn't seem to be fast enough. Any idea?
Tags (comma-separated)
Save Edits
Cancel