ABC008C コイン

C: コイン - AtCoder Beginner Contest 008 | AtCoder

(null)

コインが枚与えられる.を求める.ある数枚目が表になるか,裏になるかは枚の内,の約数であるものの個数によって変わる.枚目が表になる枚数は,表になる確率が分かればで求まる.よって

となり, が求まれば良くなった.の約数の個数を と置き,コインの中で約数と自身のみ( )で考える.
例えば約数をo, 自身をx,約数の個数をとすると x o o o, o x o o, o o x o, o o o xの パターンで表になるのは x o o oとo o x oの パターンである.

後はこれをそれぞれ計算した.


色々書いてることが怪しい.後で見直す.

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
  int n;
  cin >> n;

  vector<int> v(n);
  rep(i, n) cin >> v[i];

  sort(v.begin(), v.end());

  int cnt[105];
  memset(cnt, 0, sizeof(cnt));

  rep(i, n) {
      rep(j, n) {
          if(i == j) continue;
          if(v[i] % v[j] == 0) {
              cnt[i]++;
          }
      }
  }
  
  double ans = 0;
  rep(i, n) {
      double d = cnt[i];

      if(cnt[i] % 2 == 1) {
          double a = 1 / 2.0;
          ans += a;
      } else {
          double a = ((d + 2) / 2.0) / (d + 1);
          ans += a;
      }

  }

  cout << fixed;
  cout.precision(20);
  cout << ans << endl;

  return 0;
}
Mar 29th, 2016