contract ExampleContract { function findPrimeFactor(uint256 x) public pure returns (uint256) { // start at 2, 1 is not a prime factor // use <= because x might be prime for(uint256 i = 2; i <= x; i++) { if (x % i == 0) { return i; } } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter