Skip to content

Instantly share code, notes, and snippets.

@luciocf
Created April 30, 2019 13:27
Show Gist options
  • Save luciocf/abda06db5e718c2aedb37790e473cee7 to your computer and use it in GitHub Desktop.
Save luciocf/abda06db5e718c2aedb37790e473cee7 to your computer and use it in GitHub Desktop.
Noic - Avançado - Semana 52 - Problema 2
// Noic - Avançado - Semana 52 - Problema 2
// O(300 * sqrt(N))
#include <bits/stdc++.h>
using namespace std;
// teste de primalidade
bool isprime(int x)
{
if (x == 1) return false;
for (int i = 2; i*i <= x; i++)
if (x%i == 0)
return false;
return true;
}
int main(void)
{
int n;
scanf("%d", &n);
// loop principal
while (!isprime(n)) n++;
printf("%d\n", n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment