2 is an additive prime.
3 is an additive prime.
5 is an additive prime.
7 is an additive prime.
11 is an additive prime.
23 is an additive prime.
29 is an additive prime.
41 is an additive prime.
43 is an additive prime.
........
........
999721 is an additive prime.
999727 is an additive prime.
999749 is an additive prime.
999763 is an additive prime.
999853 is an additive prime.
999907 is an additive prime.
999961 is an additive prime.
999983 is an additive prime.
Code:
ubu@raspberrypi:~/fortran $ inxi -bSystem: Host: raspberrypi Kernel: 6.6.62+rpt-rpi-v7 arch: armv7l bits: 32 Console: pty pts/0 Distro: Raspbian GNU/Linux 12 (bookworm)Machine: Type: ARM System: Raspberry Pi 2 Model B Rev 1.1 details: BCM2835 rev: a01041 serial: 000000009dea94a9CPU: Info: quad core ARMv7 v7l [MCP] speed (MHz): avg: 900 min/max: 600/900Graphics: Device-1: bcm2835-hdmi driver: vc4_hdmi v: N/A Device-2: bcm2835-vc4 driver: vc4_drm v: N/A Display: server: No display server data found. Headless machine? tty: 122x33 API: OpenGL Message: GL data unavailable in console. Try -G --displayNetwork: Device-1: bcm2835-sdhci driver: N/A Device-2: Microchip (formerly SMSC) SMSC9512/9514 Fast Ethernet Adapter type: USB driver: smsc95xxDrives: Local Storage: total: 29.72 GiB used: 4.97 GiB (16.7%)Info: Processes: 125 Uptime: 5h 56m Memory: 996.9 MiB used: 199.4 MiB (20.0%) gpu: 76 MiB Init: systemd target: multi-user (3) Shell: Bash inxi: 3.3.26ubu@raspberrypi:~/fortran $ lsadditive_primes.f90 a_primes.f90 pi_to_100.f90ubu@raspberrypi:~/fortran $ nano additive_primes.f90ubu@raspberrypi:~/fortran $ gfortran -o additive_primes additive_primes.f90ubu@raspberrypi:~/fortran $ ./additive_primes >additive_primes.txtubu@raspberrypi:~/fortran $ nano additive_primes.txtubu@raspberrypi:~/fortran $
Code:
program additive_primes implicit none integer :: num, max_num, sum, i logical :: is_prime ! Define the maximum limit for the search max_num = 1000000 ! Adjust as needed for your search range print *, "Searching for additive primes up to", max_num do num = 2, max_num if (prime_check(num)) then sum = digit_sum(num) if (prime_check(sum)) then print *, num, "is an additive prime." end if end if end docontains ! Function to check if a number is prime logical function prime_check(n) integer, intent(in) :: n integer :: i if (n < 2) then prime_check = .false. return end if do i = 2, int(sqrt(real(n))) if (mod(n, i) == 0) then prime_check = .false. return end if
Statistics: Posted by geev03 — Sun Dec 01, 2024 6:47 pm