import java.util.*;
import java.io.*;

/**
 * Created by IntelliJ IDEA.
 * User: o_00
 * Date: 19.10.2009
 * Time: 15:49:33
 * To change this template use File | Settings | File Templates.
 */
public class Tensor_old implements Runnable {
    final String fName = "tensor";

    int nextInt ( StreamTokenizer in ) throws Exception {
        in.nextToken();
        return (int)in.nval;
    }

    int gcd( int a, int b ) {
        if ( b == 0 ) return a;
        else return gcd(b, a % b);
    }

    void print(int[][] b){
        for(int i = 0; i < b.length; i++){
            for(int j = 0; j < b[0].length; j++)
                out.print(b[i][j] + " ");
            out.println();
        }
    }

    PrintWriter out;

    public void run() {
        try {
            //StreamTokenizer in = new StreamTokenizer( new BufferedReader( new FileReader( new File( fName + ".out" ) ) ) );
            Scanner in = new Scanner( new File( fName + ".in" ) );
            out = new PrintWriter( new File( fName + ".out" ) );
            int test = 0;
            int n = in.nextInt();
            int m = in.nextInt();
            while( n != 0){
                test++;
                int[][] r = new int[n][m];
                for(int i = 0; i < n; i++)
                    for(int j = 0; j < m; j++)
                        r[i][j] = in.nextInt();
                long res = 0;
                int[][] g = new int[n + 1][m + 1];
                for(int i = 1; i < n + 1; i++)
                    for(int j = 1; j < m + 1; j++){
                        g[i][j] = gcd(r[i - 1][j - 1], g[i - 1][j]);
                        g[i][j] = gcd(g[i][j], g[i][j - 1]);
                    }
                //print(g);
                for(int p = 1; p <= n; p++) if (n % p == 0)
                    for(int q = 1; q <= m; q++) if (m % q == 0){
                        if ( (p != 1 || q != 1) && (p != n || q != m) )
                        for(int d = 1; d <= g[p][q]; d++) if ( g[p][q] % d == 0){
                            //out.println(p + " " + q + " " + d);
                            int[][] l = new int[n / p][m / q];
                            l[0][0] = d;
                            boolean ok = true;
                            for(int i = 0; i < n && ok; i++)
                                for(int j = 0; j < m && ok; j++){
                                    if (l[i / p][j / q] == 0){
                                            l[i / p][j / q] = r[i][j] / (r[i % p][j % q] / l[0][0]);
                                    }
                                    if (l[0][0] * r[i][j] != l[i / p][j / q] * r[i % p][j % q])
                                        ok = false;
                                }
                            if (ok){
                                //out.println("GOOD");
                                res++;
                            }
                        }
                    }
                out.println(res);
                n = in.nextInt();
                m = in.nextInt();
            }
            in.close();
            out.close();
        } catch ( Exception e ) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void main( String[] args ){
        new Thread( new Tensor_old() ).start();
    }
}
