Codeforces Round #136 (Div. 2) 221B - Little Elephant and Numbers Solution
Problem Link: https://codeforces.com/problemset/problem/221/B
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- int func(int a, int b) {
- string x, y;
- x = to_string(a);
- y = to_string(b);
- int flag = 0;
- for (int i = 0; i < x.size(); i++) {
- for (int j = 0; j < y.size(); j++) {
- if (x[i] == y[j]) {
- flag = 1;
- break;
- }
- }
- }
- if (flag == 1) return 1;
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n, t, i;
- cin >> n;
- set<int> st;
- for (int i = 1; i * i <= n; i++) {
- if (n % i == 0) st.insert(i), st.insert(n / i);
- }
- int ans = 0;
- for (auto it : st) {
- if (func(it, n) == 1) ans++;
- }
- cout << ans << endl;
- }
No comments