Skip to content

Instantly share code, notes, and snippets.

@yycking
Last active October 18, 2022 07:27
Show Gist options
  • Save yycking/b1f33cec63f4dc67d1c75d91350e679a to your computer and use it in GitHub Desktop.
Save yycking/b1f33cec63f4dc67d1c75d91350e679a to your computer and use it in GitHub Desktop.
輸出18~399間的質數
:- set_prolog_flag(verbose, silent).
:- initialization(main).
非質數([X | _], Value):-
Mod is Value mod X,
Mod = 0.
非質數([_ | Other], Value):-
非質數(Other, Value).
質數(Prime, From, To):-
From > To,
write(Prime).
質數(Prime, From, To):-
非質數(Prime, From),
New is From + 1,
質數(Prime, New, To).
質數(Prime, From, To):-
New is From + 1,
質數([From | Prime], New, To).
main:-
質數([17, 13, 11, 7, 5, 3, 2], 18, 399),
halt.
@yycking
Copy link
Author

yycking commented Apr 29, 2022

[397,389,383,379,373,367,359,353,349,347,337,331,317,313,311,307,293,283,281,277,271,269,263,257,251,241,239,233,229,227,223,211,199,197,193,191,181,179,173,167,163,157,151,149,139,137,131,127,113,109,107,103,101,97,89,83,79,73,71,67,61,59,53,47,43,41,37,31,29,23,19,17,13,11,7,5,3,2][Finished in 12ms]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment