Fireworks

Fireworks

题面翻译

两个烟花发射装置同时开启。第一个装置每隔 a a a 分钟发射一次烟花。第二个装置每 b b b 分钟发射一次烟花。

每个烟花在发射后的 m + 1 m + 1 m+1 分钟内都可以在天空中看到,也就是说,如果一个烟花是在装置开启后的 x x x 分钟后发射的,那么从 x x x x + m x + m x+m (包括首尾两分钟)的每一分钟都可以看到该烟花。如果一个烟花在另一个烟花 m m m 分钟后发射,则两个烟花都将在一分钟内可见。

求天空中最多可以同时看到多少枚烟花?

输入格式

每个测试由多个测试用例组成。第一行包含一个整数 t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104 ) - 测试用例的数量。

每个测试用例包含三个数 a a a b b b m m m 1 ≤ a , b , m ≤ 1 0 18 1 \le a, b, m \le 10^{18} 1a,b,m1018 )–第一个烟花发射装置、第二个烟花发射装置的发射频率,以及烟花在天空中可见的时间。

题目描述

One of the days of the hike coincided with a holiday, so in the evening at the camp, it was decided to arrange a festive fireworks display. For this purpose, the organizers of the hike bought two installations for launching fireworks and a huge number of shells for launching.

Both installations are turned on simultaneously. The first installation launches fireworks every a a a minutes (i.e., after a , 2 ⋅ a , 3 ⋅ a , … a, 2 \cdot a, 3 \cdot a, \dots a,2a,3a, minutes after launch). The second installation launches fireworks every b b b minutes (i.e., after b , 2 ⋅ b , 3 ⋅ b , … b, 2 \cdot b, 3 \cdot b, \dots b,2b,3b, minutes after launch).

Each firework is visible in the sky for m + 1 m + 1 m+1 minutes after launch, i.e., if a firework was launched after x x x minutes after the installations were turned on, it will be visible every minute from x x x to x + m x + m x+m , inclusive. If one firework was launched m m m minutes after another, both fireworks will be visible for one minute.

What is the maximum number of fireworks that could be seen in the sky at the same time?

输入格式

Each test consists of several test cases. The first line contains a single integer t t t ( 1 ≤ t ≤ 1 0 4 1 \le t \le 10^4 1t104 ) — the number of test cases. Then follow the descriptions of the test cases.

The first and only line of each test case contains integers a a a , b b b , m m m ( 1 ≤ a , b , m ≤ 1 0 18 1 \le a, b, m \le 10^{18} 1a,b,m1018 ) — the frequency of launching for the first installation, the second installation, and the time the firework is visible in the sky.

输出格式

For each set of input data, output a single number — the maximum number of fireworks that can be seen simultaneously.

样例 #1

样例输入 #1

6
6 7 4
3 4 10
7 8 56
5 6 78123459896
1 1 1
1 1 1000000000000000000

样例输出 #1

2
7
17
28645268630
4
2000000000000000002

提示

In the first set of input data, the fireworks are visible in the sky for 5 5 5 minutes. Since the first installation launches fireworks every 6 6 6 minutes, and the second one every 7 7 7 minutes, two fireworks launched from the same installation will not be visible in the sky at the same time. At the same time, after 7 7 7 minutes from the start of the holiday, one firework from the first and one from the second camp will be visible. Thus, it is possible to see no more than 2 2 2 fireworks simultaneously.

In the third set of input data, 17 17 17 fireworks will be visible after 112 112 112 minutes:

  • 9 9 9 fireworks launched from the first installation at times [ 56 , 63 , 70 , 77 , 84 , 91 , 98 , 105 , 112 56, 63, 70, 77, 84, 91, 98, 105, 112 56,63,70,77,84,91,98,105,112 ];
  • 8 8 8 fireworks launched from the second installation at times [ 56 , 64 , 72 , 80 , 88 , 96 , 104 , 112 56, 64, 72, 80, 88, 96, 104, 112 56,64,72,80,88,96,104,112 ].

题目分析

在这里插入图片描述

代码内容

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <stack>//栈
// #include <deque>//队列
// #include <queue>//堆/优先队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve()
{
    ll a,b,m;
    cin>>a>>b>>m;
    cout<<m/a+m/b+2<<endl;
}

int main()
{
    ll t;
    cin>>t;

    while(t--) solve();

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Pretty Boy Fox

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值