Project Euler/7

From Esolang
Jump to navigation Jump to search

Back to User:ProjectEuler

Project Euler Problem 7 is a problem related to prime numbers. It requires you to find the 10001st prime number.

This article is a stub, which means that it is not detailed enough and needs to be expanded. Please help us by adding some more information.

Implementations

Aheui

This may theoretically work, but it is very ineffective. It even failed on Try It Online.

박싹밤발발따따빠따발발나다뿌서더너벌벌석터너벌벌머차삭빠사빠싹삭루
수ㅇㅇㅇㅇㅇ희멍터너벌벌석차박빠삭빠싸사타야ㅇ야ㅇ오두ㅇ너벌벌서처
마ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ야오야여요뼈ㅇㅇㅇㅇㅇ어

Second try that also fails:

방박싹사뿌서
누벌벌석차박싼산빠빠따삭빠산싹삭주
타망희ㅇㅇ요나도ㅇ루석썩뻐선뻐석처산마수
ㅇㅇㅇㅇㅇㅇ볼벌선처산마숙ㅇㅇㅇ터너벌벌
ㅇㅇㅇㅇㅇ오ㅇㅇㅇ더너벌벌

Third attempt based on the C program below, and it still fails:

방박싹사뿌서
너벌벌석차ㅣ아순머희멍터
ㅇㅇㅇㅇㅇㅇ우빠쏞
ㅇㅇㅇ우ㅇㅇ삲뺘아빠따삭빠삲싹삭주
ㅇㅇㅇ어ㅇㅇ쏜ㅇㅇ루석썩뻐섢뻐석처수
ㅇㅇㅇㅇㅇㅇ솒ㅇㅇ처숙어마숞터너벌벌
ㅇㅇㅇㅇㅇ숀ㅇ더너벌벌ㅇ쏜뻐숙
ㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇㅇ쏜ㅇㅇ뻐

There may be an alternative that uses the queue.

C

This program works on Try It Online.

#include <stdio.h>
int e[10002]={0},i=0,ei=0;
int a=2;
int c=10001;
int main(){
for(a=2;c>0;++a){
 if(ei==0){e[ei]=a;++ei;--c;}
 else{
  for(i=0;e[i]*e[i]<=a;++i){
   if(a%e[i]==0){break;}
  }
  if(a%e[i]!=0){e[ei]=a;++ei;--c;}
 }
}
printf("%d",a-1);
return 0;
}


External resources

  • Prime number on Wolfram Mathworld
  • A000040, a related sequence on OEIS. The 10001st term is the solution.
  • Problem 7 on Project Euler Official Website (not available)
  • Problem 7 on Project Euler Mirror