We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
//My code by C++,solving by the solution divide and conquer#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<algorithm>usingnamespacestd;boolpalindrome(longlongn){longlongfirst_num=n;longlongreverse=0;while(n>0){longlongnum=n%10;reverse=reverse*10+num;n/=10;}return(first_num==reverse);}boolchecker(intk){for(inti=999;i>=100;i--){if(k%i==0&&k/i>=100&&k/i<=999){returntrue;}}returnfalse;}signedmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */longlongt;cin>>t;while(t--){longlongn;cin>>n;for(longlongi=n-1;i>=101101;i--){if(palindrome(i)==true&&checker(i)==true){cout<<i<<endl;i=INT8_MIN;//get out the "for loop" when find i }}}return(0^0);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #4: Largest palindrome product
You are viewing a single comment's thread. Return to all comments →