两条线段有交的充要条件是每一维上都有交qwq
因为每个线段都平行一个坐标轴,他的表示应该是(l~r,x1,x2,x3…xn)
A和B相交和A和C相交显然没有任何关系
算粗A,B相交的概率,乘上两两的组合数就行了
两条线段相交的概率画一下柿子就行了吧
然后写个高精..
code:
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxl = 1100;
ll gcd(ll a,ll b){return !a?b:gcd(b%a,a);}
int n,d;
struct Num
{
ll a[maxl]; int len;
}fz,fm,temp;
ll Mod(Num &x,ll b)
{
ll tmp=0;
for(int i=x.len;i>=1;i--)
tmp=(tmp*10ll+x.a[i])%b;
return tmp;
}
void div(Num &x,ll b)
{
int len=x.len; ll tmp=0;
for(int i=len;i>=1;i--)
{
tmp=tmp*10ll+x.a[i];
x.a[i]=tmp/b; tmp%=b;
}
while(!x.a[len]) len--;
x.len=len;
}
void mul(Num &x,ll b)
{
int len=x.len;
for(int i=len;i>=1;i--) x.a[i]*=b;
for(int i=1;i<=len;i++) x.a[i+1]+=x.a[i]/10ll,x.a[i]%=10ll;
while(x.a[len+1])
{
len++;
x.a[len+1]+=x.a[len]/10ll,x.a[len]%=10ll;
}
x.len=len;
}
void add(Num &x,Num y)
{
int len=max(x.len,y.len);
for(int i=1;i<=len;i++)
{
x.a[i]+=y.a[i];
x.a[i+1]+=x.a[i]/10ll,x.a[i]%=10ll;
}
if(x.a[len+1]) len++;
x.len=len;
}
void MUL(ll b)
{
ll g=gcd(Mod(fm,b),b);
ll tmp=b/g; if(g>1ll) div(fm,g);
if(tmp>1ll) mul(fz,tmp);
}
void DIV(ll b)
{
ll g=gcd(Mod(fz,b),b);
ll tmp=b/g; if(g>1ll) div(fz,g);
if(tmp>1ll) mul(fm,tmp);
}
void output(Num &x){for(int i=x.len;i>=1;i--) putchar('0'+x.a[i]);}
void Out()
{
MUL((ll)d*(d-1)/2ll);
output(fz);
if(!(fm.len==1&&fm.a[1]==1)) putchar('/'),output(fm);
putchar('\n');
}
int main()
{
while(scanf("%d%d",&n,&d)!=EOF)
{
memset(fz.a,0,sizeof fz.a); fz.a[1]=1ll,fz.len=1;
fm=temp=fz;
mul(fz,n); mul(fz,n);
temp.len=2,temp.a[1]=6ll,temp.a[2]=1ll; add(fz,temp);
temp.len=1,temp.a[1]=8ll,temp.a[2]=0ll; mul(temp,n); add(fz,temp);
DIV(n); DIV(n); DIV(9ll);
for(int i=3;i<=d;i++) DIV(n);
Out();
}
return 0;
}