This is program i written but it is working till 100000 and thrn it is so slow