【April Fools Day Contest 2016B】【暴力】Scrambled 至少满足其一 模a余b

B. Scrambled
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt dya is zreo), adn yuo wsah teh diehss on dya D if adn olny if terhe etsixs an iednx i scuh taht D mod M[i] = R[i], otwsehrie yuor rmootmae deos it. Yuo lkie teh cncepot, btu yuor rmotaome's cuinnng simle meaks yuo ssecupt sthnoemig, so yuo itennd to vefriy teh fnerisas of teh aemnrgeet.

Yuo aer geivn ayarrs M adn R. Cuaclatle teh pceanregte of dyas on wchih yuo edn up dnoig teh wisahng. Amsuse taht yuo hvae iiiftlneny mnay dyas aehad of yuo.

Input

The first line of input contains a single integer N (1 ≤ N ≤ 16).

The second and third lines of input contain N integers each, all between 0 and 16, inclusive, and represent arrays M and R, respectively. All M[i] are positive, for each i R[i] < M[i].

Output

Output a single real number. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 4.

Examples
input
1
2
0
output
0.500000
input
2
2 3
1 0
output
0.666667


#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<ctype.h>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<bitset>
#include<algorithm>
#include<time.h>
using namespace std;
void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); }
#define MS(x,y) memset(x,y,sizeof(x))
#define MC(x,y) memcpy(x,y,sizeof(x))
#define MP(x,y) make_pair(x,y)
#define ls o<<1
#define rs o<<1|1
typedef long long LL;
typedef unsigned long long UL;
typedef unsigned int UI;
template <class T1, class T2>inline void gmax(T1 &a, T2 b) { if (b>a)a = b; }
template <class T1, class T2>inline void gmin(T1 &a, T2 b) { if (b<a)a = b; }
const int N = 20, M = 0, Z = 1e9 + 7, ms63 = 0x3f3f3f3f;
int a[N], b[N];
int n;
int main()
{
	while (~scanf("%d", &n))
	{
		for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
		for (int i = 1; i <= n; ++i)scanf("%d", &b[i]);
		double ans = 0;
		for (int i = 1; i <= 1000000; ++i)
		{
			bool flag = 1;
			for (int j = 1; j <= n; ++j)
			{
				if (i%a[j] == b[j]) { flag = 0; break; }
			}
			if (flag==0)ans += 1e-6;
		}
		printf("%.15f\n", ans);
	}
	return 0;
}
/*
【题意】
有n(16)个取模关系a[] b[]
我们有,对于x,至少有一个i使得 x mod a[i] == b[i]
问你,合法x的概率是多少。

【类型】
暴力

【分析】
这题因为精度要求很低,所以我们可以直接暴力。
暴力循环LCM内的数,或者暴力一个精度允许的范围。
这道题就可以AC啦!


*/


你可能感兴趣的:(codeforces,暴力,题库-CF)