Educational Codeforces Round 63 (Rated for Div. 2)C. Alarm Clocks Everywhere【数论】

编程入门 行业动态 更新时间:2024-10-28 13:21:49

C. Alarm Clocks Everywhere

思路:题意是给你n个任务,你可以任意选择一个开始时间,并从给定序列中选择一个间隔,使得能完成这n个任务。

就是求出来n-1个差,然后求出来最大公约数,然后判断这m个间隔是否存在一个是这个数的因子即可。

#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1|1
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 10;
ll a[maxn], p[maxn];
ll d[maxn];
ll gcd(ll x, ll y)
{return y == 0 ? x : gcd(y, x % y);
}int main()
{int n, m;scanf("%d%d", &n, &m);for(int i = 1; i <= n; ++i){scanf("%I64d", &a[i]);}for(int i = 2; i <= n; ++i){d[i] = a[i] - a[i - 1];}ll ans = gcd(d[2], d[3]);for(int i = 4; i <= n; ++i){ans = gcd(ans, d[i]);}for(int i = 1; i <= m; ++i){scanf("%I64d", &p[i]);}ll y, pos;bool flag = false;for(int i = 1; i <= m; ++i){if(ans % p[i] == 0){pos = i;flag = true;break;}}if(flag){printf("YES\n");printf("%I64d %I64d\n", a[1], pos);}elseprintf("NO\n");return 0;
}

 

更多推荐

数论,Codeforces,Educational,Rated,Clocks

本文发布于:2023-05-29 16:44:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/348719.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数论   Codeforces   Educational   Rated   Clocks

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!