Created
April 30, 2019 13:27
-
-
Save luciocf/abda06db5e718c2aedb37790e473cee7 to your computer and use it in GitHub Desktop.
Noic - Avançado - Semana 52 - Problema 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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