Advertisement
a53

CifreGen4

a53
Feb 4th, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4. long long int n,m,p=1;
  5. int cifra_m(long long int n,long long int m)
  6. {
  7. int c,cant=n%10;
  8. n/=10;
  9. while(n)
  10. {
  11. c=n%10;
  12. if(abs(c-cant)<2||c>=m||cant>=m)
  13. return 0;
  14. cant=c;
  15. n/=10;
  16. }
  17. return 1;
  18. }
  19. int main()
  20. {
  21. cin>>n>>m;
  22. int nr=0;
  23. for(int i=1;i<=n;i++)
  24. {
  25. nr=nr*10+(m-1);
  26. p*=10;
  27. }
  28. p/=10;
  29. for(long long int i=p;i<=nr;i++)
  30. if(cifra_m(i,m))
  31. cout<<i<<'\n';
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement