Eat - Code - Sleep - Repeat
#include #include using namespace std;int main(){ int t, n; cin >> t; while(t--) { cin >> n; if( n < 10 ) { if( n==2 || n==3 || n==5 || n==7) cout << n << " eh primo\n"; else cout << n << " nao eh primo\n"; } else{ int root = sqrt(n*1.0); int nonPrime = 0; if( n%2 == 0) nonPrime = 1; else for(int i=3; i<=root; i+=2) { if(n%i == 0){ nonPrime = 1; break; } } if( nonPrime == 0) cout << n << " eh primo\n"; else cout << n << " nao eh primo\n"; } } return 0;}
#includeint main(){ int i,n,j,x,y=0; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d",&x); for(j=2;j<x;j++) { if(x%j==0) y++; else continue; } if(y!=0) printf("%d nao eh primo\n",x); else printf("%d eh primo\n",x); x=0; y=0; } return 0;}reply..
#include
ReplyDelete#include
using namespace std;
int main()
{
int t, n;
cin >> t;
while(t--)
{
cin >> n;
if( n < 10 )
{
if( n==2 || n==3 || n==5 || n==7)
cout << n << " eh primo\n";
else
cout << n << " nao eh primo\n";
}
else{
int root = sqrt(n*1.0);
int nonPrime = 0;
if( n%2 == 0) nonPrime = 1;
else
for(int i=3; i<=root; i+=2)
{
if(n%i == 0){
nonPrime = 1;
break;
}
}
if( nonPrime == 0)
cout << n << " eh primo\n";
else
cout << n << " nao eh primo\n";
}
}
return 0;
}
#include
ReplyDeleteint main()
{
int i,n,j,x,y=0;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%d",&x);
for(j=2;j<x;j++)
{
if(x%j==0)
y++;
else
continue;
}
if(y!=0)
printf("%d nao eh primo\n",x);
else
printf("%d eh primo\n",x);
x=0;
y=0;
}
return 0;
}
reply..