日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVa 10375 - Choose and divide(唯一分解定理)

發布時間:2024/4/17 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVa 10375 - Choose and divide(唯一分解定理) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

鏈接:

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1316

?

題意:

已知C(m,n) = m!/(n!(m-n)!),輸入整數p, q, r, s(p≥q,r≥s,p,q,r,s≤10000),計算C(p,q)/C(r,s)。
輸出保證不超過1e8,保留5位小數。

?

分析:

首先,求出10000以內的所有素數prime,然后用數組e表示當前結果的唯一分解式中各個素數的指數。
例如,e={1,0,2,0,0,0,…}表示21*52=50。具體實現見代碼。

?

代碼:

1 import java.io.*; 2 import java.util.*; 3 4 public class Main { 5 static int e[]; 6 static ArrayList<Integer> prime = new ArrayList<Integer>(); 7 8 static void getPrimeNumber(int up) { // 獲取素數 9 boolean isp[] = new boolean[up+5]; 10 Arrays.fill(isp, true); 11 int u = (int)Math.sqrt(up + 0.5); 12 for(int t = 2; t <= u; t++) if(isp[t]) { 13 for(int i = t * t; i <= up; i += t) isp[i] = false; 14 } 15 for(int i = 2; i <= up; i++) if(isp[i]) prime.add(i); 16 } 17 18 static void addInteger(int n, int d) { // 乘以或除以n. d=1表示乘,d=-1表示除 19 for(int i = 0; i < prime.size(); i++) { 20 while(n % prime.get(i) == 0) { 21 n /= prime.get(i); 22 e[i] += d; 23 } 24 if(n == 1) break; 25 } 26 } 27 28 static void addFactorial(int n, int d) { // 把結果乘以(n!)的d次方 29 for(int i = 1; i <= n; i++) addInteger(i, d); 30 } 31 32 public static void main(String args[]) { 33 Scanner cin = new Scanner(new BufferedInputStream(System.in)); 34 getPrimeNumber(10000); 35 e = new int[prime.size()]; 36 37 while(cin.hasNext()) { 38 int p = cin.nextInt(); 39 int q = cin.nextInt(); 40 int r = cin.nextInt(); 41 int s = cin.nextInt(); 42 43 Arrays.fill(e, 0); 44 addFactorial(p, 1); 45 addFactorial(q, -1); 46 addFactorial(p-q, -1); 47 addFactorial(r, -1); 48 addFactorial(s, 1); 49 addFactorial(r-s, 1); 50 double ans = 1; 51 for(int i = 0; i < prime.size(); i++) 52 ans *= Math.pow(prime.get(i), e[i]); 53 System.out.printf("%.5f\n", ans); 54 } 55 cin.close(); 56 } 57 }

?

轉載于:https://www.cnblogs.com/hkxy125/p/8855457.html

總結

以上是生活随笔為你收集整理的UVa 10375 - Choose and divide(唯一分解定理)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。