- You shouldn’t start at zero
- Your
flag
condition should be!flag
After fixing that, you will always get 1, because it’s relatively prime to everything. Try starting at z - 1
and decrementing if you want the biggest one. You should also just break;
instead of keeping a flag.