Cod sursa(job #1613270)

Utilizator DobosDobos Paul Dobos Data 25 februarie 2016 11:55:48
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("numere6.in");
ofstream fout("numere6.out");
const int MOD = 9973;
const int NMAX = 9005;
int M[2][NMAX];
int V[10];
inline int Div(int x){
    int n = 1,d = x;
    for(int i = 2; i <= d; i++){
        if(d % i == 0){
            V[n] = i;
            n ++;

            while(x % i == 0 && i < 10){
                x /= i;
            }
        }
    }
    if(x == 1)
        return n - 1;
    return -1;

}

int main()
{
    int a,b,n;
    fin >> a >> b;
    n = Div(b);
    if(n == -1){
        fout << 0;
        return 0;
    }
    for(int i = 1; i <= n; i++)
        M[0][V[i]] = 1;
    int x = 0,y = 1;
    for(int i = 2; i <= a; i++){
        x = 1 - x;
        y = 1 - y;
        for(int j = 1; j <= n; j++)
            M[y][V[j]] = 0;
        for(int j = 1; j <= n; j++){
            for(int p = 1; p <= n && V[p] < 10; p++){
                if(V[j]%V[p] == 0){
                    M[y][V[j]] = (M[y][V[j]] + M[x][V[j]/V[p]]) % MOD;
                }
            }
        }

    }
    fout << M[y][b];
    return 0;
}