B - Das Blinkenlights

博客围绕两盏按固定间隔闪烁的灯展开。两灯初始都关闭,第一盏在t=p,2p,3p…秒闪烁,第二盏在t=q,2q,3q…秒闪烁。输入p、q和最大考虑时间s,要求编写程序判断在1到s秒内两灯是否会同时闪烁,输出yes或no。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

There are two lights that blink at regular intervals. When each one blinks, it turns on and then immediately back off; they don’t toggle. They are both off at time t=0. The first one blinks at t=p,2p,3p,… seconds; the second one blinks at t=q,2q,3q,… seconds. Once they start, they both keep blinking forever. It is very exciting to see them blink at the same time (on the same second). But your patience is going to run out eventually, in s seconds. Will they blink at same time between t=1 and t=s

(inclusive)? Write a program that can answer this question, quick, before they start blinking again!

\includegraphics[width=0.8\textwidth ]{sample}

Figure 1: Illustration of the sample inputs. A black circle means the light is off, a white circle means the light blinks at that second. The arrows above point out times when both lights blink.

Input

Input consists of one line containing three space-separated integers p

, q, and s. The bounds are 1≤p,q≤100 and 1≤s≤10000. The first light blinks every p seconds, the second every q seconds. The value of s

represents the maximum number of seconds to consider when determining if the two lights blink at the same time.

Output

Output yes if the two lights blink on the same second between time 1

and time s

, or no otherwise.

Sample Input 1Sample Output 1
2 5 20
yes
Sample Input 2Sample Output 2
4 3 11
no

 

#include<iostream>
using namespace std;
int main()
{
    int p,q,n;
    cin>>p>>q>>n;
    int ok=0;
    for(int i=1; i<=n; i++)
    {
        if(i%p==0&&i%q==0)
        {
            ok=1;
            break;
        }
    }
    if(ok==1) cout<<"yes"<<endl;
    else cout<<"no"<<endl;
    return 0;
}

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值