for(i=0;i< String (1234455....upto >=500 digits);i++)
This is insane. Even with a 19 digit number (long precision), and running 1 million loops per second, it will take more than a hundred thousand years to complete. At about 24 digits it will take a time greater than the lifetime of the entire universe so far (13.5 billion years). What exactly do you really want to do here?