# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98038 | 2019-02-20T02:17:15 Z | Sharon | Brunhilda’s Birthday (BOI13_brunhilda) | Java 11 | 0 ms | 0 KB |
import java.util.*; public class BrunhildasBirthday { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int t = scan.nextInt(); int[] p = new int[n]; long prod = 1; for(int i = 0; i < n; i++){ p[i] = scan.nextInt(); if(Long.MAX_VALUE/p[i] > prod) prod *= p[i]; else break; } for(int q = 1; q <= t; q++){ int m = scan.nextInt(); if(m >= prod){ System.out.println("oo"); continue; } int ans = 0; while(m > 0){ ans++; for(int i = n-1; i >= 0; i--){ if(m%p[i] != 0){ m -= m%p[i]; break; } } } System.out.println(ans); } } }