CodeForces 787A The Monster

来源:互联网 发布:胡歌顶级时尚资源知乎 编辑:程序博客网 时间:2024/06/05 04:39

题目链接:http://codeforces.com/contest/787/problem/A
题意:有两个序列,一个是由b+a*x组成,一个是由d+c*y组成,问你他们第一个相等的是哪个
解析:直接暴力枚举了x,然后去判断y是否存在

#include <iostream>#include <cstdio>#include <algorithm>#include <vector>#include <cstring>#include <queue>#include <cmath>#include <map>using namespace std;const int maxn = 1e6+100;const int inf = 0x7fffffff;const int mod = 1e9;int main(void){    int a,b,c,d;    scanf("%d %d %d %d",&a,&b,&c,&d);    int flag = 1;    for(int i=0;i<maxn;i++)    {        int t1 = b+a*i;        if((t1-d)%c==0 && t1>=d)        {            flag = 0;            printf("%d\n",t1);            break;        }    }    if(flag)        puts("-1");    return 0;}
0 0
原创粉丝点击