POJ2103 Jackpot(容斥+高精度)

本文深入探讨了游戏开发领域的核心技术,包括游戏引擎、图形渲染、3D空间视频等关键概念和实践,为游戏开发者提供深入的技术指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Jackpot
Time Limit: 20000MS Memory Limit: 64000K
Total Submissions: 1044 Accepted: 216
Case Time Limit: 2000MS

Description

The Great Dodgers company has recently developed a brand-new playing machine. 
You put a coin into the machine and pull the handle. After that it chooses some integer number. If the chosen number is zero you win a jackpot. In the other case the machine tries to divide the chosen number by the lucky numbers p1 , p2 , . . . , pn . If at least one of the remainders is zero --- you win. 
Great Dodgers want to calculate the probability of winning on their machine. They tried to do it, but failed. So Great Dodgers hired you to write a program that calculates the corresponding probability. 
Unfortunately, probability theory does not allow you to assume that all integer numbers have equal probability. But one mathematician hinted you that the required probability can be approximated as the following limit: 
limk→∞(Sk/2k+1).

Here S k is the number of integers between -k and k that are divisible by at least one of the lucky numbers.

Input

Input file contains n --- the number of lucky numbers (1 <= n <= 16), followed by n lucky numbers (1 <= pi <= 10 9 ).

Output

It is clear that the requested probability is rational. Output it as an irreducible fraction. 
On the first line of the output file print the numerator of the winning probability. On the second line print its denominator. Both numerator and denominator must be printed without leading zeroes. Remember that the fraction must be irreducible.

Sample Input

2
4 6

Sample Output

1
3
题意:给定n个数,向老虎机中投入一枚硬币,机器返回一个值X,如果X能被至少一个Pi整除,则获胜,求 lim k→∞ (S k /2k+1). Sk表示-k到k中能获胜的X的个数,答案用最简分数表示。
思路:简单的容斥,用JAVA大数搞定,只是要注意代码的常数级优化。TLE了一晚。。。
import java.util.*;
import java.math.*;

public class Main {
	public static BigInteger gcd(BigInteger a, BigInteger b){
		 if(b.equals(BigInteger.valueOf(0))) return a;
		 else return gcd(b,a.mod(b)); 
	}
	private static Scanner in;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BigInteger []num = new BigInteger[20];
		in = new Scanner(System.in);
		while(in.hasNextInt()){
			int n = in.nextInt();
			BigInteger fz = BigInteger.ZERO;
			BigInteger fm = BigInteger.ONE;
			BigInteger LCM,tmp;
			for(int i = 0; i < n; i++) {
				int k = in.nextInt();
				num[i] = BigInteger.valueOf(k);
				tmp = fm.gcd(num[i]);
				fm = fm.divide(tmp).multiply(num[i]);
			}
			
			for(int i = 1; i < (1<<n); i++) {
				int cnt = 0;
				LCM = BigInteger.ONE;
				for(int j = 0; j < n; j++) {
					if((i&(1<<j))>0) {
						tmp = num[j].gcd(LCM);
						LCM = LCM.divide(tmp).multiply(num[j]);
						cnt++;
					}
				}
				LCM = fm.divide(LCM);
				if((cnt&1)!=0) {
					fz = fz.add(LCM);
				}else{
					fz = fz.subtract(LCM);
				}
			}
			BigInteger GCD = gcd(fz,fm);
			fm = fm.divide(GCD);
			fz = fz.divide(GCD);
			System.out.println(fz);
			System.out.println(fm);
		}
	}
}


内容概要:本文详细介绍了基于FPGA的144输出通道可切换电压源系统的设计与实现,涵盖系统总体架构、FPGA硬件设计、上位机软件设计以及系统集成方案。系统由上位机控制软件(PC端)、FPGA控制核心和高压输出模块(144通道)三部分组成。FPGA硬件设计部分详细描述了Verilog代码实现,包括PWM生成模块、UART通信模块和温度监控模块。硬件设计说明中提及了FPGA选型、PWM生成方式、通信接口、高压输出模块和保护电路的设计要点。上位机软件采用Python编写,实现了设备连接、命令发送、序列控制等功能,并提供了一个图形用户界面(GUI)用于方便的操作和配置。 适合人群:具备一定硬件设计和编程基础的电子工程师、FPGA开发者及科研人员。 使用场景及目标:①适用于需要精确控制多通道电压输出的实验环境或工业应用场景;②帮助用户理解和掌握FPGA在复杂控制系统中的应用,包括PWM控制、UART通信及多通道信号处理;③为研究人员提供一个可扩展的平台,用于测试和验证不同的电压源控制算法和策略。 阅读建议:由于涉及硬件和软件两方面的内容,建议读者先熟悉FPGA基础知识和Verilog语言,同时具备一定的Python编程经验。在阅读过程中,应结合硬件电路图和代码注释,逐步理解系统的各个组成部分及其相互关系。此外,实际动手搭建和调试该系统将有助于加深对整个设计的理解。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值