Codeforces Round #136 (Div. 2) 221B - Little Elephant and Numbers Solution


  

 Problem Link:  https://codeforces.com/problemset/problem/221/B

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. int func(int a, int b) {
  10. string x, y;
  11. x = to_string(a);
  12. y = to_string(b);
  13. int flag = 0;
  14. for (int i = 0; i < x.size(); i++) {
  15. for (int j = 0; j < y.size(); j++) {
  16. if (x[i] == y[j]) {
  17. flag = 1;
  18. break;
  19. }
  20. }
  21. }
  22. if (flag == 1) return 1;
  23. }
  24. signed main() {
  25. ios_base::sync_with_stdio(0);
  26. cin.tie(0);
  27. int n, t, i;
  28. cin >> n;
  29. set<int> st;
  30. for (int i = 1; i * i <= n; i++) {
  31. if (n % i == 0) st.insert(i), st.insert(n / i);
  32. }
  33. int ans = 0;
  34. for (auto it : st) {
  35. if (func(it, n) == 1) ans++;
  36. }
  37. cout << ans << endl;
  38. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.