Math
Last Updated: 2021-12-15
isPrime
public static boolean isPrime(int number) {
if(number == 1 ){
return false;
}
for (int i = 2; i < number; i++) {
if (number % i == 0) {
return false;
}
}
return true;
}
Digital Root
https://en.wikipedia.org/wiki/Digital_root#Congruence_formula
Fibonacci
>>> def fibonacci():
... a, b = 0, 1
... while True:
... yield b
... a, b = b, a + b
...
>>> c = fibonacci()
>>> c.next()
1
>>> c.next()
1
>>> c.next()
2
>>> c.next()
3
>>> c.next()
5
class Solution {
public int fibonacci(int n) {
int a = 0, b = 1;
while(--n > 0) {
int c = a + b;
a = b;
b = c;
}
return a;
}
}