Jump to content

Topic pentru discutii


Dyablox
 Share

Recommended Posts

aa da si trebuia sa pun for mic

 ia-l de aici

 

#include <iostream>
using namespace std;

boolean prim
{
  int x = 0;
  for (i = 2; i < n-1; i++)
      if (n%i != 0) x++;
  if (n-2 == x)
  {
      return true;
  }

  else
  {
      return false;
  }
}
while(a != 0)
{
	x = x * 10 + a % 10;
        a = a / 10; //asta este inversul lui a
}

int main()
{
    boolean();
    int n, x, a, i;
cin >> a ;
cin >> x;
    while(a != 0)
{
	x = x * 10 + a % 10;
        a = a / 10; //asta este inversul lui a
}

}

nu merge editat lol

Edited by Bilosul
Link to comment
Share on other sites

Codul meu e mai optim:

 

#include <iostream>

using namespace std;

bool prim(int x)
{
    if(x == 2)
        return true;
    for(int i = 2; i <= x / 2; i++) 
        if(x % i == 0)
            return false;
    return true;
}

int invers(int n)
{
    int m = 0;
    while (n != 0)
    	{
    		m = m * 10 + n % 10;
    		n = n / 10;
    	}
    return m;
}

int main()
{
    cin << b;
    if(prim(b) && prim(invers(b))) cout << "DA";
    else cout << "NU";
    return 0;
}

 

Link to comment
Share on other sites

12 minutes ago, rTn Dyablox VIP said:

Codul meu e mai optim:

 


#include <iostream>

using namespace std;

bool prim(int x)
{
    if(x == 2)
        return true;
    for(int i = 2; i <= x / 2; i++) 
        if(x % i == 0)
            return false;
    return true;
}

int invers(int n)
{
    int m = 0;
    while (n != 0)
    	{
    		m = m * 10 + n % 10;
    		n = n / 10;
    	}
    return m;
}

int main()
{
    cin << b;
    if(prim(b) && prim(invers(b))) cout << "DA";
    else cout << "NU";
    return 0;
}

 

1hYwIHI.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.