HolyC0w

lab2_primefactors

Apr 11th, 2023
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void primeFactors(int n);
  2. void primeFactors(int n) {
  3.   while (n % 2 == 0) {
  4.     Serial.println(2);
  5.     n /= 2;
  6.   }
  7.  
  8.   for (int i = 3; i * i <= n; i += 2) {
  9.     while (n % i == 0) {
  10.       Serial.println(String(i));
  11.       n /= i;
  12.     }
  13.   }
  14.   if (n > 2) Serial.println(String(n));
  15. }
  16.  
  17. void setup() {
  18.   Serial.begin(9600);
  19.   int n = 315;
  20.   primeFactors(n);
  21. }
  22. void loop() {
  23. }
Advertisement
Add Comment
Please, Sign In to add comment