Is there a less naive way to find the (group size) of 2^n MOD prime (>2)? I am not sure of the correct mathematical name of the feature I am looking at. Its been a long time since I did math at school.   seems to concerned with this sort of thing, but leaves me unsure that I have understood what is written. Below I use '%' as MOD and '^' as 'raised to the power of'.  And am quite wordy. For all primes &gt; 2, there is a sequence {2^n%prime, for all integer n, 0 to infinity}. That is { 2^0 % prime = 1, 2^1 % prime = 2, .. 2^(prime-1) % prime = 1, 2^prime % prime = 2, ..} 2^((prime-1) * m)%prime = 1 and 2^(prime * m)%prime = 2 for all integer m. if the prime is 7 however, the sequence is made up of two instance of a shorter sequence thus: 2^0%7 = 1, 2^1%7 = 2, 2^2%7 = 4, 2^3%7 = 1, 2^4%7 = 2, 2^5%7 = 4, 2^6%7 = 1 and then 2^(6 * n)%7 is still 1; but the are extra values that are also another set of at (2^(3+6*n)%7) So the cycle-length(prime) is what I have been calling the first n &gt; 0 where 2^n mod prime is 1. I have inserted some code that calculates this by trial until repetition.. with some trivial uses of it. long cycleLength(long prime) {     long remainder = 1 ;     long length = 0 ;      do {         length++ ; //#define FAST_MODULO #ifdef FAST_MODULO         remainder = (remainder+remainder)%prime ; #else         remainder += remainder ;         if (remainder &gt; prime) remainder -= prime ; #endif         if (remainder == 1)             return length ;     } while (length &lt; prime/2) ;      return prime-1 ;}  size_t pow_of_2(unsigned n) {     size_t result = 1 ;     size_t pow = 2 ;      while(n)     {         if (n &amp; 1) result *= pow ;         pow *= pow ;         n /= 2;     }     return result ; }  #include &lt;iostream&gt; using std::cout ;  int main(int ac, char **av) {     long prime = 17 ;      cout &lt;&lt; &quot;cycleLength(17) = &quot; &lt;&lt; cycleLength(17) &lt;&lt; '\n';      cout &lt;&lt; &quot;2^16 = &quot; &lt;&lt; pow_of_2(16) &lt;&lt; '\n' ;     cout &lt;&lt; &quot;2^33 = &quot; &lt;&lt; pow_of_2(33) &lt;&lt; '\n' ;      cout &lt;&lt; &quot;33 % CL(17) = &quot; &lt;&lt; 33 % cycleLength(17)           &lt;&lt; &quot;, 2^(33 % CL(17)) % 17 = &quot; &lt;&lt; pow_of_2(33%cycleLength(17)) % 17 &lt;&lt; '\n' ;     cout &lt;&lt; &quot;2^33 % 17 = &quot; &lt;&lt; pow_of_2(33)%17 &lt;&lt; '\n' ;     cout &lt;&lt; std::endl ; }  I have observed that cycles are either length (prime-1) or divisor of (prime-1). So the run-time is reduced by stopping at (n == prime/2) and returning (prime-1) as that is the only case remaining; and the code is about 25% quicker as a result. The algorithm is currently O(N) time complexity. I am hoping for clues or insight that might reduce this. Thanks for reading this.
Algorithms for computing multiplicative order modulo $n$ If I take the $k \in \mathbb{N}$ power of 10 and mod it by a large prime, I notice that the remainders repeat at some point.  For instance $10^k mod~7$ seems to repeat every $8$th value of $k$.  Given $k$ (the power of ten), and a large prime number $p$, how can I compute the size of the cycle?  I tried writing a python script that computes the first instance of a repeat. However, I don't know if this works since a single instance of a repeat may not necessarily mean a full cycle.
Is there a way to head/tail a document and get the reverse output; because you don't know how many lines there are in a document?  I.e. I just want to get everything but the first 2 lines of foo.txt to append to another document. A half covered lens Let's say there's an object in front of a convex lens. I have a piece of paper behind the lens at the right location such that it will the lens will form an image on the paper. The object is illuminating.  Now if I put another piece of paper right before the lens, and cover up half of the lens. The image, instead of only half being visible, it will actually remain the same. The only difference is that it will be dimmer.  Now, the question is what if I remove the paper at the location where the image forms, and put my eye there. What will I see? Will I see the piece of paper which is blocking half of the lens at all? Does that mean I will just "see through" the paper?  I wanted to try this out myself, but unfortunately I don't have a lens besides me. How many of Trelawney's prophecies have come true? Throughout the Harry Potter series, Professor Trelawney makes many different prophecies and predictions. Although most of them are implied to be nonsense, often enough they still get fulfilled. Which ones have come true? Which ones have been proven false? Which ones are still possible?  How many of Trelawney's prophecies have come true?  I'm not asking if Divination in Harry Potter is real, or what it is. I am asking for a finite list of which of Trelawney's prophecies came true, and which ones didn't. Every season near the trade deadline, we see teams that are out of it trading expensive players and/or free agents-to-be, typically for younger players or prospects.  For example, Matt Garza, set to become a free agent after the season, was traded to the Rangers for a few prospects.  It made sense for the Cubs to trade Garza, because he wasn't under contract any further than this season, and thus doesn't have much value to them.  Compare Garza to someone like Mike Trout, who is likely the most valuable property in baseball, given his skill and inexpensive cost over the next several years.  There's no way the Angels would trade him, because he'll be the cost-controlled centerpiece of the team for years to come.  However, with the Angels out of it this year, what if they wanted to trade Trout to a contender (say the Pirates), but only for the remainder of this season?  That is, they'd get several top prospects now, and would have an agreement with the Pirates that they'd trade him back in the offseason (for something pretty worthless, say for a journeyman minor leaguer).  The Pirates get Trout for the stretch run and are happy to give up a few prospects.  Trout doesn't have much value to the Angels this year, but he has a ton of value for next year.  So they get a few prospects for him, in exchange for the part of his career which has very little value to them.  So in effect, the Pirates are renting or borrowing him for the remainder of 2013.  Why don't trades like this happen?  Are there any rules prohibiting trades like this? Bash Script if condition is always true Adding admin-ajax.php to the frontend. Good or bad idea? I love admin-ajax.php. But I hate having to localize in order to point frontend scripts to it, and I wish there was an equivalent, easy-to-find file for themes. (It also just bothers me to see frontend requests go through "/wp-admin/". No practical reason, just looks ugly IMO.)  So I've simply copied admin-ajax.php to the root dir at "/ajax.php", adjusted the include paths and removed the WP_ADMIN constant definition. Seems to work like gangbusters (I can now just direct all my frontend AJAX requests to /ajax.php! And I can still use the normal wp_ajax hooks in my plugins!).  But is this safe? What might go wrong? Since this isn't built into core, I assume there's a good reason as to why not. But looking through the code, I can't see any immediate problems.   You're smart--tell me if this approach is crazy. Or if there's a simpler method that I'm overlooking. Looking for a function $f$ that is $n$-differentiable, but $f^{(n)}$ is not continuous I am looking for a real valued function of real variable that is $n$-differentiable, but whose $n$th derivative is not continuous.  This is my function:  $f_n(x) = x^{n+1} \cdot \sin{\frac{1}{x}}$, if $x \neq 0$ and 0, if $x=0$. $n\in \{0,1,2,\ldots\}$ For example, if $n=0$, $f_0$ it's continuous and non diferentiable in $0$. Skype doesn't work in Ubuntu 14.04 Assume I have the following list:  foo = ['a', 'b', 'c', 'd', 'e']   What is the simplest way to retrieve an item at random from this list? Proxying fake domain to a localhost port I'd like to do much the same thing described at  for web app development purposes, but with the twist that I'd like requests to fakedomain.com:80 to be routed to localhost:8080, say, so that I don't have to actually use my development machine's port 80.  I'd welcome answers that take the form of:   Small changes to configuration files like /etc/hosts, and/or An easy-to-configure proxy server I could run   Note:  takes the approach of setting a firewall rule to forward all incoming traffic on port 80 to port 20559. That may be an acceptable solution, but ideally, I'd like to forward only a specific domain + port combination. How do I call a .NET assembly from C/C++? Suppose I am writing an application in C++ and C#.  I want to write the low level parts in C++ and write the high level logic in C#.  How can I load a .NET assembly from my C++ program and start calling methods and accessing the properties of my C# classes? Debugging a custom-bib bst file that crashes on book items I created my own bibliography file with custom-bib (makebst), but when I run it with a reference to a book I get:  $ bibtex PhD [...normal output] Database file #1: PhD.bib You can't pop an empty literal stack for entry oecd2001brc while executing---line 1504 of file wdsphd.bst   The only thing on that line is a high-level ITERATE call.   The style was created with these options:  %% merlin.mbs  (with options: `head,exlang,annote,seq-no,nm-rvvc,dt-beg,yr-par,xmth,tit-qq,qx,bt-qq,vol-bf,volp-sp,num-xser,pub-date,isbn,issn,doi,english,pp,ord,url,url-nl,nfss,,{}') %% english.mbs  (with options: `exlang,annote,seq-no,nm-rvvc,dt-beg,yr-par,xmth,tit-qq,qx,bt-qq,vol-bf,volp-sp,num-xser,pub-date,isbn,issn,doi,english,pp,ord,url,url-nl,nfss,,{}') %% merlin.mbs  (with options: `tail,exlang,annote,seq-no,nm-rvvc,dt-beg,yr-par,xmth,tit-qq,qx,bt-qq,vol-bf,volp-sp,num-xser,pub-date,isbn,issn,doi,english,pp,ord,url,url-nl,nfss,,{}')   The code for book items looks like:  FUNCTION {book} { output.bibitem   author empty$     { format.editors "author and editor" output.check     }     { format.authors output.nonnull       crossref missing$         { "author and editor" editor either.or.check }         'skip$       if$     }   if$   format.btitle "title" output.check   crossref missing$     { format.bvolume output       new.block       format.number.series output       new.sentence       format.publisher.address output     }     {       new.block       format.book.crossref output.nonnull     }   if$   format.edition output   format.isbn output   format.doi output   new.block   format.note output   fin.entry   write.url }   And this is the entry:  @book{oecd2001brc,  author = {OECD},  doi = {10.1787/9789264193550-en},  isbn = {9789264186903},  publisher = {OECD Publishing},  title = {{Biological Resource Centres: Underpinning the future of life sciences and biotechnology}},  url = {http://www.oecd-ilibrary.org/science-and-technology/biological-resource-centres\_9789264193550-en},  year = {2001} }   Is there a way to get a better stacktrace from bibtex? What I have now doesn 't really tell me what is going on. If it can be fixed simply, help would also be appreciated. Who in the DC Universe can stop Superman if he has a breakdown? Is there anything or anyone in the DC universe that can defeat Superman just in case he goes berserk on everybody?  Maybe Batman stores kryptonite in his Cave or something. I don't know if Batman actually has kyptonite, the example was just a theoretical example.  Who can stop Superman if needed, and how? I converted a raster image to vector in Illustrator CS6 using Image Trace then the Expand option, though when I save as an svg the image looks embossed. I suspect it's due to the layer background being white and the paths not lining up, but I'm unsure how to fix it or prove that theory without manually having to adjust every path.   This is how it looks in Illustrator before I export it:    The image looks like this when saved/exported with art optimized option: I am trying to define an rgb color. More specifically I want to create this color    which in rgb mode it's (98,190,177).  I tried to define this color using the following code  \documentclass{standalone}  \usepackage{tikz}  \begin{document}  \definecolor{tank}{rgb}{0.098,0.190,0.177}  %\definecolor{tank}{rgb}{98,190,177}  \begin{tikzpicture}   \coordinate (tank) at (0,0);   \draw[red, fill=tank] (-2,0.5)--(-0.5,1)--(0.5,1)--(2,0.5)--(2,-0.5)--(0.5,-1)--(-0.5,-1)--(-2,-0.5)--cycle;  \end{tikzpicture} \end{document}   but the output is totally different from what I am trying to achieve    I also tried to use \definecolor{tank}{rgb}{98,190,177} but I get no color at all. How to properly define an rgb color? How do I search for questions with specific tags?       For more information about searching, see &quot;&quot; in the . Can polymorph and true polymorph change a PC's race and sex? Flip x and y axes in Excel graph This should not be very difficult, but I cannot figure out how to do it.  I have a table similar to this     %low %high  0   0   12  1  13   26  ... 19  90   94 20  95  100   When I graph it, excel defaults to having the first column on the x axis and plotting the second and third column as y values. I want the first column to be on the y axis instead. I assume there is an easy way to do this, but I cannot figure it out. Most of the things I have found from searching have suggested the "Switch Row/Column" button, but that does something else.  Thanks for the help. Evaluating $\int \sqrt{1 + t^2} dt$? How do we solve (i.e. get the closed form of) $\int \sqrt{1 + t^2} dt$ ?   shows the closed form of it but not the steps in solving it.  I think I need some algebraic trick..   I thought of some hyperbolic functions and their derivatives and equalities:  If I make $ t = \sinh x$, then I can reduce the integral to  $$ \int \cosh ^2 x dx $$ though I'm not sure if this is valid. But from here, I cannot go on evaluating the integral... Is there any utility to check whether my laptop battery is in healthy condition or not? Is there any utility available on Ubuntu to check whether laptop battery is in healthy condition or not?