Using fact all numbers in [2, 6] are not happy (and all not happy numbers end on a cycle that hits this interval):

```
bool isHappy(int n) {
while(n>6){
int next = 0;
while(n){next+=(n%10)*(n%10); n/=10;}
n = next;
}
return n==1;
}
```