Problem (D.SDUT 2018 Autumn Individual Contest - H)

Problem D.

滴答滴答---题目链接

Deposits Input file: deposits.in Output file: deposits.out Time limit: 3 seconds Memory limit: 256 megabytes

Financial crisis forced many central banks deposit large amounts of cash to accounts of investment and savings banks in order to provide liquidity and save credit markets.

Central bank of Flatland is planning to put n deposits to the market. Each deposit is characterized by its amount ai . The banks provide requests for deposits to the market.

Currently there are m requests for deposits. Each request is characterized by its length bi days. The regulations of Flatland’s market authorities require each deposit to be refinanced by equal integer amount each day. That means that a deposit with amount a and a request with length b match each other if and only if a is divisible by b. Given information about deposits and requests,

find the number of deposit-request pairs that match each other. Input The first line of the input file contains n — the number of deposits (1 ≤ n ≤ 100 000). The second line contains n integer numbers: a1, a2, . . . , an (1 ≤ ai ≤ 106 ).

The third line of the input file contains m — the number of requests (1 ≤ m ≤ 100 000).

The forth line contains m integer numbers: b1, b2, . . . , bm (1 ≤ bi ≤ 106 ).

Output Output one number — the number of matching pairs.

Example deposits.in deposits.out

4

A  3 4 5 6

4

B  1 1 2 3 12

The following pairs match each other:

(3, 1) twice (as (a1, b1) and as (a1, b2)), (3, 3), (4, 1) twice, (4, 2), (5, 1) twice, (6, 1) twice, (6, 2), and (6, 3).

题意:当且仅当A可被B整除。则计算有多少个

#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int N=1000011;
long long int a[N],b[N];
int main()
{
    freopen("deposits.in","r",stdin);
    freopen("deposits.out","w",stdout);
    long long int n,m,x,y,j,c,i,sum=0;
    memset(b,0,sizeof(b));
    memset(a,0,sizeof(a));
    scanf("%lld",&n);
    for( i=1; i<=n; i++)
    {
        scanf("%lld",&y);
        a[y]++;
    }
    scanf("%lld",&m);
    for( i=1; i<=m; i++)
    {

        scanf("%lld",&x);
        b[x]++;
    }
    long long int ans=0;
    for(i=1; i<=1000000; i++)
    {

        if(b[i])
        {
            c=0;
            for( j=i; j<=1000000; j=j+i)
            {
                if(a[j]!=0)
                {
                    c+=a[j];
                }
            }
            ans+=c*b[i];
        }
    }
    printf("%lld\n",ans);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值