We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 25: Running Time and Complexity
Day 25: Running Time and Complexity
Sort by
recency
|
812 Discussions
|
Please Login in order to post a comment
include
include
const char* is_prime(int n) { if (n <= 1) { return "Not prime"; } if (n <= 3) { return "Prime"; } if (n % 2 == 0 || n % 3 == 0) { return "Not prime"; }
}
int main() { int n; printf("Enter a number: "); scanf("%d", &n);
return 0; }
t=int(input()) for _ in range(t): n=int(input()) if n<=1: print('Not prime') else: for i in range(2,int(n**0.5)+1): if(n%i)==0: print('Not prime') break else: print('Prime')
javaScript Solution
function processData(input) { const numbers = input.split('\n').slice(1).map(Number);
numbers.forEach(number => { console.log(isPrime(number) ? 'Prime' : 'Not prime'); }); }
function isPrime(num) { if (num <= 1) return false; if (num <= 3) return true; if (num % 2 === 0 || num % 3 === 0) return false;
for (let i = 5; i * i <= num; i += 6) { if (num % i === 0 || num % (i + 2) === 0) return false; }
return true; } `