import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; /** * * NAIPC 2014 Problem: GCDs * * Go through all possible values from gcd(a) to max(a_i) and see if we can * obtain that gcd (basically O(n), with a relatively large constant in the * worst case, but still a constant) * * Based on the fact that gcd(L,R)=g can be extended (to either side) only by * multiples of g * * Only optimization is that we mark all gcds we see and do not check for them * again * * @author darko.aleksic * */ public class GCDs_darko { private void work() { Scanner sc = new Scanner(new BufferedReader(new InputStreamReader( System.in))); int[] a = new int[100010]; while (true) { int n = sc.nextInt(); if (n == 0) { break; } boolean[] seen = new boolean[101]; a[0] = sc.nextInt(); int g = a[0]; seen[g] = true; int max = a[0]; for (int i = 1; i < n; i++) { a[i] = sc.nextInt(); seen[a[i]] = true; if (a[i] > max) { max = a[i]; } g = gcd(g, a[i]); seen[g] = true; } for (int i = g + 1; i <= max; i++) { if (!seen[i]) { boolean fst = true; for (int j = 0; j < n; j++) { if (a[j] % i == 0) { if (fst) { fst = false; g = a[j]; } else { g = gcd(g, a[j]); seen[g] = true; if (g == i) { break; } } } else { fst = true; } } } } int res = 0; for (int i = 1; i <= max; i++) { if (seen[i]) { res++; } } System.out.println(res); } } private int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public static void main(String[] args) { new GCDs_darko().work(); } }