Skip to content

Instantly share code, notes, and snippets.

@shashank21j
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shashank21j/1011e4204279e522cdcc to your computer and use it in GitHub Desktop.
Save shashank21j/1011e4204279e522cdcc to your computer and use it in GitHub Desktop.

Fixing the error in cpp code

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        const int cpy = n;
        
        int numdig = 0;
        
        while (n > 0)
        {
            int current = n % 10;
            if (current != 0 && cpy % current == 0) numdig++;
            n /= 10;
        }
        
        cout << numdig << endl;
    }
    return 0;
}

Python

N = input()

for i in range(N):
    num = raw_input()
    count = 0
    for digit in num:
        if digit != '0' and int(num) % int(digit) == 0:
            count = count + 1
    print count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment