From d1adf3c2c2f21d71c0ed9ae50253876d383fbb19 Mon Sep 17 00:00:00 2001 From: Summer-the-coder Date: Wed, 1 Oct 2025 16:56:08 +0300 Subject: [PATCH] Update pi.c: performance improvement --- .../performance/numerical/src/nativeInterop/cinterop/pi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c b/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c index d22f3994ecd2a..c7babaca83ee3 100644 --- a/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c +++ b/kotlin-native/performance/numerical/src/nativeInterop/cinterop/pi.c @@ -74,12 +74,12 @@ static int pow_mod(int a, int b, int m) static int is_prime(int n) { int r, i; - if ((n % 2) == 0) + if ((n % 2) == 0 || (n % 3) == 0) return 0; r = (int) (sqrt(n)); - for (i = 3; i <= r; i += 2) - if ((n % i) == 0) + for (i = 5; i <= r; i += 6) + if ((n % i) == 0 || (n % (i + 2)) == 0) return 0; return 1; }