Trees in a Wood UVA - 10214 欧拉函数模板

太坑惹,,,没用longlong各种WA

 1 #include <iostream>
 2 #include <string.h>
 3 #include <cstdio>
 4 #include <math.h>
 5 #define SIGMA_SIZE 26
 6 #pragma warning ( disable : 4996 )
 7 
 8 using namespace std;
 9 typedef long long LL;
10 
11 inline int Max(int a,int b) { return a>b?a:b; }
12 inline int Min(int a,int b) { return a>b?b:a; }
13 const int inf = 0x3f3f3f3f;
14 const int maxn = 2e3+5;
15 const int maxk = 2e6+5;
16 
17 int gcd(int a, int b)
18 { return b==0?a:gcd(b,a%b); }
19 int A, B;
20 int oula[maxn];
21 bool g[maxn][maxn];
22 
23 void init()
24 {
25     memset( g, false, sizeof(g) );
26     int i, j;
27     for ( i = 0; i < maxn; i++ )
28         oula[i] = i;
29 
30     for ( i = 2; i < maxn; i++ )
31         if ( oula[i] == i )
32             for ( j = i; j < maxn; j+=i )
33                 oula[j] = oula[j]/i*(i-1);
34 
35     for( i = 1; i < maxn; i++ )
36         for( j = 1; j < maxn; j++ )
37             if( gcd(i,j) == 1 )
38                 g[i][j] = true;
39 }
40 
41 int main()
42 {
43     init();
44     while ( ~scanf("%d%d", &A, &B)&&A&&B )
45     {
46         if( A > B ) swap(A,B);    
47         double sum = 0;
48 
49         for ( int i = 1; i <= A; i++ )
50         {
51             sum += oula[i]*(B/i);
52             int tmp = B%i;
53             for( int j = 1; j <= tmp; j++ )
54                 if ( g[i][j] )
55                     sum++;
56         }
57         
58         double ans = sum*2 + 2;
59         double all = (unsigned long long)A*B*2+A+B;
60         printf( "%.7lf\n", ans/all );
61     }
62 
63     return 0;
64 }

 

posted @ 2018-03-30 20:59  LBNOQYX  阅读(114)  评论(0编辑  收藏  举报