Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int primo(int n) {
- int i, potenzialmente_primo;
- potenzialmente_primo = n % 2 || n == 2;
- i = 3;
- while (potenzialmente_primo && i * i <= n) {
- if (n % i == 0)
- potenzialmente_primo = 0;
- i += 2;
- }
- return potenzialmente_primo;
- }
- // 6
- // 1 2 3 5 7
- int f(int n){//x = 6
- while(1 != primo(n))
- n--;
- return n;
- }
- int main(void){
- int M,n,np=0;
- printf("Inserisci M\n");
- scanf("%d",&M);
- for(n=2;n<=M;n++){
- if(primo(n)){
- np++;
- }
- printf("%d %d %d\n",n,f(n),np);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement