Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int feltes(int n);
- int prime(int n);
- int main(void) {
- int i, j, P[20], n, ans;
- for (i = 0; i < 20; i++)
- P[i] = 0;
- puts("feltes:");
- for (i = 2; i < 100; i++)
- if (feltes(i)) printf("%d\n", i);
- puts("prime:");
- srand((unsigned) time(NULL));
- for (i = 0; i < 20; i++) {
- do {
- n = (int) ((rand() / ((double) RAND_MAX + 1.)) * 100) + 1;
- ans = prime(n);
- if (ans != 1) continue;
- for (j = 0; j < i; j++)
- if (P[j] == n) goto cont;
- P[i] = n;
- break;
- cont: continue;
- } while (1);
- printf("%d\n", P[i]);
- }
- return 0;
- }
- int feltes(int n) {
- int i, j;
- unsigned long long rui;
- if (n < 2) return 0;
- if (n == 2) return 1;
- for (i = 2; i < n - 1; i++) {
- rui = i;
- for (j = 1; j < n - 1; j++) {
- rui *= i;
- if (rui < 0) return 0;
- }
- if (rui % n != 1) {
- return 0;
- } else {
- return 1;
- }
- }
- return 0;
- }
- int prime(int n) {
- int i;
- if (n < 2) return 0;
- if (n == 2) return 1;
- for (i = 2; i * i <= n; i++)
- if (n % i == 0) return 0;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement