整數的唯一分解定理
對于一個大于1正整數n可以分解質因數:
約數個數
,
其中a1、a2、a3…ak是p1、p2、p3,…pk的指數,
eg:
給定n個正整數aiai,請你輸出這些數的乘積的約數個數,答案對109+7取模,
輸入格式
第一行包含整數n,
接下來n行,每行包含一個整數aiai,
輸出格式
輸出一個整數,表示所給正整數的乘積的約數個數,答案需對109+7109+7取模,
資料范圍
1≤n≤1001≤n≤100,
1≤ai≤2?1091≤ai≤2?109
輸入樣例:
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); } }
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/95255.html
標籤:其他
