A243977 a(n) is the largest run of identical digits that n^k can end with for some k, or 0 if there is no limit to such runs.
3, 1, 2, 1, 1, 1, 3, 1, 0, 2, 3, 3, 2, 1, 1, 5, 1, 2, 0, 1, 3, 1, 1, 1, 1, 1, 3, 1, 0, 3, 1, 4, 2, 1, 1, 3, 3, 3, 0, 1, 3, 1, 2, 1, 1, 1, 3, 1, 0, 1, 3
Offset: 2
Examples
For a(1), 2^k ends in 1 identical digit when k = 1, 2 identical digits when k = 18, and 3 identical digits when k = 39. 2^k doesn't end in 4 identical digits for any k. Thus a(1) = 3.
Programs
-
PARI
a(n,p)=lst=[];for(c=0,10^p,m=n^c%10^p;if(vecsearch(vecsort(lst),m),for(i=1,#lst,if(vecextract(lst,2^(i-1),)==[m],return([c,c-i+1]))));if(!vecsearch(vecsort(lst),m),lst=concat(lst,m))) hup(n)=if(n%10==0,return(0));ww=[];p=2;for(ii=1,a(n,p)[1],ww=concat(ww,ii));while(p<100,v=ww;w=[];for(q=1,#v,h=digits(n^v[q]%10^p);if(#h==p&&(vecmin(h)==vecmax(h)),w=concat(w,v[q])));if(w,ww=[];for(k=1,#w,j=w[k];while(j<=a(n,p+1)[1],ww=concat(ww,j);j+=a(n,p)[2]));ww=vecsort(ww,,8);p++);if(!w,return(p-1))) n=2;while(n<100,print1(hup(n),", ");n++)
-
Python
def a(n,p): lst = [] for c in range(10**p+1): m = n**c%10**p if m in lst: return [c,c-lst.index(m)] else: lst.append(m) def cou(n): if n % 10 == 0: return 0 ww = [] p = 2 aa = a(n,p)[0] ww.extend(range(aa)) while p < 100: newlst = ww w = [] for i in newlst: m = n**i%10**p if len(str(m))==p and m%int('1'*p)==0: w.append(i) if w: ww = [] for k in w: j = k while j <= a(n,p+1)[0]: ww.append(j) j += a(n,p)[1] ww.sort() p += 1 else: return p-1 n = 2 while n < 100: if cou(n): print(cou(n),end=', ') else: print(0,end=', ') n += 1
Extensions
Programs corrected and improved by Derek Orr, Aug 18 2014
Comments