Created
July 22, 2025 01:15
-
-
Save MurageKibicho/1353d8d6839c6902e374c8044205b8e1 to your computer and use it in GitHub Desktop.
Test for the largest cubic prime factor
This file contains hidden or 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
// Online C compiler to run C program online | |
#include <stdio.h> | |
int FindCubeInPrimeFactorization(int n) | |
{ | |
if (n == 0) return 0; // 0³ = 0 | |
if (n == 1) return 1; // 1³ = 1 | |
int cube = 1; | |
for(int p = 2; p * p <= n; p++) | |
{ | |
if(n % p == 0) | |
{ | |
int exponent = 0; | |
while(n % p == 0) | |
{ | |
exponent++; | |
n /= p; | |
} | |
// Add p^(exponent / 3) to the cube | |
for(int i = 0; i < exponent / 3; i++) | |
{ | |
cube *= p; | |
} | |
} | |
} | |
// If remaining n is a prime > 1, exponent is 1 (no cube contribution) | |
return cube; | |
} | |
int main() { | |
// Write C code here | |
for(int i = 10000; i < 11000; i++) | |
printf("%d : %d\n",i,FindCubeInPrimeFactorization(i)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment