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 \(p_1 , p_2 , \cdots , p_n\) . 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:

\[\lim_{k \to \infty}\frac{S_k}{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 \le n \le 16)\), followed by \(n\) lucky numbers \((1 \le p_i \le 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

第一次用java写程序,为了不打高精度(因为必须涉及高精除),代码几乎是蒯的。\(2^N\)枚举,相互求\(lcm\),贡献即为\(\frac{1}{lcm}\),然后用容斥原理合答案即可。

ACMjava1H速成戳这里

import java.math.*;
import java.util.*;
public class Main
{
static BigInteger d,ret,temp,yy;
static int n,dd;
static boolean mark = true;
static BigInteger[] a = new BigInteger[20];
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
n = in.nextInt();
temp = BigInteger.ONE;
ret = BigInteger.ZERO;
for (int i = 0;i < n;++i)
{
int k = in.nextInt();
a[i] = BigInteger.valueOf(k);
d = temp.gcd(a[i]);
temp = temp.multiply(a[i]).divide(d);
}
for (int i = 1;i < (1<<n);++i)
{
mark = false; yy = BigInteger.ONE;
for (int j = 0;j < n;++j) if (((1 << j) & i) > 0) { mark = !mark; d = a[j].gcd(yy); yy = yy.multiply(a[j]).divide(d); }
if (mark) ret = ret.add(temp.divide(yy));
else ret = ret.subtract(temp.divide(yy));
}
d = ret.gcd(temp);
System.out.println(ret.divide(d));
System.out.println(temp.divide(d));
}
}

POJ2103 Jackpot的更多相关文章

  1. UVa 10684 - The jackpot

    题目大意:给一个序列,求最大连续和. 用sum[i]表示前i个元素之和,那么以第i个元素结尾的最大连续和就是sum[i]-sum[j] (j<i)的最大值,也就是找前i-1个位置sum[]的最小 ...

  2. 【2005-2006 ACM-ICPC, NEERC, Moscow Subregional Contest】Problem J. Jack-pot

    简单dfs,差分一下A数组和建出字典树能写得更方便,若不这么做代码时就会像我一样难受. #include<cstdio> #include<cstring> #include& ...

  3. Web测试的常用测试用例与知识

    1. Web测试中关于登录的测试 2. 搜索功能测试用例设计 3. 翻页功能测试用例 4. 输入框的测试 5. Web测试的常用的检查点 6. 用户及权限管理功能常规测试方法 7. Web测试之兼容性 ...

  4. web测试常用的用例及知识

      1.      Web测试中关于登录的测试... 1 2.      搜索功能测试用例设计... 2 3.      翻页功能测试用例... 3 4.      输入框的测试... 5 5.    ...

  5. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习

    # Practice Exercises for Functions # Solve each of the practice exercises below. # 1.Write a Python ...

  6. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)C. Bear and Poker

                                                  C. Bear and Poker                                     ...

  7. iOS开发之 几本书

    <object_c 编程之道书> <iOS 7 UI Transition Guide> iOS开发指南:从零基础到App Store上架[国内第一本iOS架构设计图书,涵盖i ...

  8. C Primer Plus(第五版)7

    第 7 章 C 控制语句:分支和跳转 在本章中你将学习下列内容: · 关键字:if(如果),else(否则),switch(切换),continue(继续),break(中断), case(情况),d ...

  9. Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 1) A. Bear and Poker 分解

    A. Bear and Poker Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/573/pro ...

随机推荐

  1. 分享功能使用的UIPopoverController在iOS9 过期,替换为popoverPresentationController

    记录一下 以备以后用到的时候拿出来看看.以前使用的: 1 if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom ...

  2. E: Sub-process /usr/bin/dpkg returned an error code (1)

    E: Sub-process /usr/bin/dpkg returned an error code (1) 错误描述 dpkg: error processing archive /var/cac ...

  3. C++学习(五)

    一.拷贝构造函数和拷贝赋值运算符1.拷贝构造:用一个已有的对象,构造和它同类型的副本对象——克隆.2.形如class X {  X (const X& that) { ... }};的构造函数 ...

  4. Android开发——构建自定义组件

    Android中,你的应用程序程序与View类组件有着一种固定的联系,例如按钮(Button). 文本框(TextView), 可编辑文本框(EditText), 列表框(ListView), 复选框 ...

  5. yii中的自定义组件

    yii中的自定义组件(组件就是一些自定义的公用类) 1.在项目目录中的protected/components/Xxxx.php 2.在Xxxx.php中定义一个类,类名必须与文件名相同 3.控制器中 ...

  6. Windows Server 2008安装Memcached笔记

    分布式缓存系统Memcached简介与实践 缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了数据库负载.缓存是解决这个问题的好办法.但是ASP.NET中的虽然 ...

  7. 关于layoutSubviews以及drawRect方法

    首先两个方法都是异步执行.layoutSubviews方便数据计算,drawRect方便视图重绘. layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubvi ...

  8. Javascript模仿C语言的链表实现(增删改查),并且使用控制台输入输出

    Js新手最近在研究Js数据结构,刚好看到链表实现这一块儿,觉得有些资料和自己理解的有冲突,于是借着自己以前一点点C语言的基础,用Javascript模仿了C的链表实现,并且用了process.stdi ...

  9. JavaScript中的Date

    Date 对象用于处理日期和时间. var myDate=new Date() Date 对象会自动把当前日期和时间保存为其初始值. Date常用方法有: myDate.getYear(); //获取 ...

  10. cocos2d-x v3.0的window平台搭建和编译成andriod程序

    首先添加这个地址到系统环境变量,path 然后打开CMD,输入如下语句 现在就可以创建一个新项目了 这样一个空的cocos2d-x v3.0的项目就创建好了 接下来编译andriod程序 先在系统环境 ...