How do i do the same in c++?

The solution shows in java, is there a way to implement it in c++? how should I go about it?

Hey @shibangi
Refer to this How to solve SPOJ JULKA problem in C++?