Advertisement
Farjana_akter

Untitled

Aug 10th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. vector<long long int>m;
  5.  
  6. bool kap(long long int l)
  7. {
  8. // cout<<"dhukse"<<endl;
  9. long long int n,a,b,j,k;
  10.  
  11. n=l*l;
  12. string s=to_string(n);
  13. // cout<<"STRING "<<s<<endl;
  14. a=0,b=0;
  15. for(j=0; j<s.length(); j++)
  16. {
  17. a=a*10+(s[j]-'0');
  18. // cout<<a<<endl;
  19. b=0;
  20. for(k=j+1; k<s.length(); k++)
  21. {
  22. b=b*10+(s[k]-'0');
  23. }
  24. // cout<<b<<endl;
  25. if(a>0 && b>0 && a+b==l)
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31.  
  32. int main()
  33. {
  34. long long int cas,x,y,i,j,k,t,flag=1;
  35. cin>>t;
  36. for(cas=1; cas<=t; cas++)
  37. {
  38. if(cas>1)
  39. cout<<endl;
  40. cin>>x>>y;
  41. flag=0;
  42. cout<<"case #"<<cas<<endl;
  43. for(i=x; i<=y; i++)
  44. {
  45. if(kap(i))
  46. {
  47. // cout<<"a"<<endl;
  48. cout<<i<<endl;
  49. flag=1;
  50. }
  51. }
  52. if(flag==0)
  53. cout<<"no kaprekar numbers"<<endl;
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement