agc047 A - Integer Product

 

 

 

 链接 https://atcoder.jp/contests/agc047/tasks/agc047_a

题意:给N个数 问两两相乘是整数的pair的个数

每个数最多有九位小数

题解 

把每个数乘1e9 然后判断乘积%1e18是不是0就行了

然后要快速处理这个

我们发现1e18 有18个2和18个5 处理素因子就行了

 

不过有个地方需要注意啊  double转为ll的时候,会丢失精度 ,我也不知道具体原理,我打印了一下确实有些数会有误差

这时候用llround函数可以避免这个误差  长知识了 这就是atcoder 爱了爱了

#include<bits/stdc++.h>
//#include<tr1::unordered_map>
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,a,n) for(int i=n;i>=a;--i)
#define pb push_back
#define fi first
#define se second
#define io std::ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
const int  maxn=1e5+50;
ll gcd(ll a,ll b)
{
    return b?gcd(b,a%b):a;
}
ll qpow(ll a,ll n)
{
    ll r=1%P;
    for (a%=P; n; a=a*a%P,n>>=1)if(n&1)r=r*a%P;
    return r;
}
bool cmp(int a,int b)
{
  return a>b;
}
ll mp[65][65];
ll ans;
void fen(ll x)
{   ll ans2=0;
    ll ans5=0;
    while(x%5==0)
    {
      x/=5;
      ans5++;
    }
    while(x%2==0)
    {
      x/=2;
      ans2++;
    }
    for(int i=0;i<=64;i++)
      for(int j=0;j<=64;j++)
      {
        if(ans2+i>=18&&ans5+j>=18)
           ans+=mp[i][j];
      }
    mp[ans2][ans5]++;
}
int main()
{  io;
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
     double x;
     cin>>x;
     ll y=llround(x*1000000000.0);
     fen(y);
   }
   cout<<ans<<endl;
}

 

posted @ 2020-09-08 23:19  摸鱼选手LLF  阅读(224)  评论(0)    收藏  举报