Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Izabella Maria Cavalcanti Melo;
- 1º periodo de Engenharia da Computação - CIn UFPE;
- imcm@cin.ufpe.br;
- 21/04/2017
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int primo(x) {
- int a=1, b, div=0;
- while(a<=x) {
- b = x%a; //se x mod a for igual a zero, a é divisor de x
- if (b==0) {
- div = div+1;
- a = a + 1; }
- else a = a + 1; }
- return div; }
- int main()
- {
- int t, n, i, j=0, k=0;
- scanf("%d", &t);
- for (i=t; i>0; i--) {
- scanf("%d", &n);
- if (n==1) printf("Nem primo nem quase primo\n");
- else if (primo(n)==2) printf("Primo\n");
- else if (primo(n)!=2) {
- /* para todo quase primo n par, em n/p, p é necessariamente 2, pois se p for multiplo de 2, não será primo;
- e se p não for 2 nem um multiplo de 2, não será par */
- if (n%2==0) {
- if ((primo(n/2)==2)&&(2!=n/2)) printf("Quase primo\n");
- else printf("Nem primo nem quase primo\n"); }
- else if (n%2!=0) {
- while (j<=n) {
- j=j+1;
- if ((n%j==0)&&(primo(j)==2)) {
- k=n/j;
- if ((primo(k)==2)&&(k!=j)) {
- printf("Quase primo\n");
- break; } }
- else if (j==n+1)
- printf("Nem primo nem quase primo\n");
- }
- }
- }
- j=0;
- k=0;
- }
- return 0;
- }
- //imcm
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement