@atul: Anurag's code has illustrated the idea of O(sqrt(E)) solution. One more thing to optimize is that we can safely break after finding the first factor of E which is less than sqrt(E). So the code could be changed to:
#include<cmath>#include<cstdio>#include<iostream>#include<cstring>#include<cstdlib>using namespace std;#define INFY 1000000007int main() { int n, i, j; int val, minDiv, minDis; while(1) { cin >> n; minDis = INFY; for (i = n; i <= n+2; i++) { *for (j = sqrt(i * 1.0); j > 0; j--)* { if (i % j == 0 && minDis > (i/j - j) ) { minDis = i/j - j; minDiv = j; val = i; *break;* } } } cout<<val<<" "<<minDiv<<" "<<val/minDiv<<endl; } //system("pause"); return 0; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.