對於一個大於1正整數n能夠分解質因數:java
。spa
其中a一、a二、a3…ak是p一、p二、p3,…pk的指數。3d
eg:code
給定n個正整數aiai,請你輸出這些數的乘積的約數個數,答案對109+7取模。xml
第一行包含整數n。blog
接下來n行,每行包含一個整數aiai。get
輸出一個整數,表示所給正整數的乘積的約數個數,答案需對109+7109+7取模。it
1≤n≤1001≤n≤100,
1≤ai≤2∗1091≤ai≤2∗109class
3 2 6 8
12
代碼:
import java.util.*; public class Main{ static final int N=(int)1e9+7; static Map<Integer, Integer> map=new HashMap<Integer, Integer>(); static int t; public static void main(String[] args) { Scanner scan=new Scanner(System.in); t=scan.nextInt(); while(t-->0){ //求解每一個質因子的指數 int n=scan.nextInt(); for(int i=2;i<=n/i;i++){ if(n%i==0){ while(n%i==0){ n/=i; if(map.get(i)==null) map.put(i, 1); else map.put(i, map.get(i)+1); } } } if(n>1) { if(map.get(n)==null) map.put(n, 1); else map.put(n, map.get(n)+1); } } //求約數個數 long res=1; Set<Integer> key=map.keySet(); Iterator<Integer> it=key.iterator(); while(it.hasNext()){ int s=it.next(); res=res*(map.get(s)+1)%N; } System.out.println(res); } }