We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #130: Composites with prime repunit property
Project Euler #130: Composites with prime repunit property
Sort by
recency
|
14 Discussions
|
Please Login in order to post a comment
my entire code is right but i dont know why its failing i have checked taking more complex values can anyone help me out with this!
Scanner sc=new Scanner(System.in); long num=1; int j,val,k,c=0,r=0; int n1,n2; n1=sc.nextInt(); n2=sc.nextInt(); int arr[]=new int[50]; for(int i=4;i<22;i++) { j=i; num=1; c=0; while(j>1) { num=num+(long)(Math.pow(10, j-1)); j--;
}
k=5; while(k5;x--) { if(k%x==0 && (k-1)%i==0) { c++; break; }
} if(c>0) { arr[r]=k; r++; } } k++; } } Arrays.sort(arr);
I'm wondering if someone solved this with Java (or any ather JVM language). I had a timeout on 7 test cases. After I reimplemented my solution in C using 128-bit integer I could complete.
For those who passed all test cases, could you please give a hint on whether we should approach this problem by
Iterating on starting from to (
+= 2
and skipping multiples of ) and feed them to primality testing (e.g. Miller-Rabin), orGenerating all composite numbers from primes except and ? (e.g. using a heap)
Do we need to make use of the observation that is the least common multiple between and if ?
I was using the first approach and only passed the first 6 test cases. My implementataion of the
A(i)
function was by performingcurr = (curr * 10 + 1) % i
on each iteration step, and the upper bound of this function is which is not very nice.EDIT: An observation, that for example , where is one of the valid answers, but , and are all invalid answers. I wonder if there is any pattern there. Also, it is curious that is the largest prime we need for up to .
why 41 is not a part of answer ? It also satisfied all condition for 2 to 1000.
is anybody know how to calculate A(i)? Thnks.!