CF 345A Mike and Frog
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib> #define LL long long using namespace std; LL m,ans; LL gcd(LL a,LL b){
if(!b) return a;
return gcd(b,a%b);
} /*
since the f(x) be an fuction from a num x to y.
so it may be a cricle.
*/ void solve(LL &ansv,LL &sumv){
LL h,a,x,y,ans=;
scanf("%I64d%I64d%I64d%I64d",&h,&a,&x,&y);
for(int i=;i<=m;i++){
h=(h*x%m+y)%m;
if(h==a){
ansv=(LL)i; //how many seconds it would take for us to arrive 'a' from 'h'
goto L;
}
}
puts("-1");
exit();
L:h=a;
sumv=-;
for(int i=;i<=m;i++){
h=(h*x%m+y)%m; //how many seconds it would take for us to arrive 'a' from 'a'
if(h==a){
sumv=(LL)i;
return;
}
}
} /*
a1 + k1*a2 = b1 + k2*b2 ans = a1 (mod a2)
ans = b1 (mod b2)
*/ int main(){
scanf("%I64d",&m);
LL a1,a2,b1,b2;
solve(a1,a2);
solve(b1,b2);
if(a1==b1) ans=a1;
else if(a2==-&&b2==-){
puts("-1");
return ;
}
else if(a2==-&&a1>b1&&(a1-b1)%b2==) ans=a1;
else if(b2==-&&b1>a1&&(b1-a1)%a2==) ans=b1;
else if(a2==-||b2==-){
puts("-1");
return ;
}
else{
LL k1;
for(k1=;k1<=m;k1++)
if((a1+k1*a2-b1)%b2==){
ans=a1+k1*a2;
if(ans>=b1) break;
}
if(k1>m) ans=-;
}
printf("%I64d\n",ans);
return ;
}
Code
CF 345A Mike and Frog的更多相关文章
- CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&&当然暴力is also no problem)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
A. Mike and Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pr ...
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
- cf#305 Mike and Foam(容斥)
C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- cf 547B. Mike and Feet dp
题意: n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1 对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度 求:for ea ...
- codeforces #305 A Mike and Frog
挺简单的题目,但是有一堆恶心的边界 在刨去恶心的边界之后: 假定我们知道两边的循环节为b1,b2 其中h第一次到达目标的时间为a1,a2 又知道对于答案t t=a1+b1*t1=a2+b2*t2 不妨 ...
- codeforces 547A Mike and Frog
近期都是这样的题呢. . .... 哎 開始想纯暴力(体如今跳出循环t>=那里.,,,)..,.随着数据变大.. ...(t=499981500166是能够的),,,..,,23333333 超 ...
- 「日常训练」 Mike and Frog (CFR305D2C)
题意与分析 (Codeforces 548C) 我开始以为是一条数学题,死活不知道怎么做,无奈看题解,才知这是一条暴力,思维江化了- - 题意大概是这样的: 两个东西的初始高度分别为h1,h2&quo ...
- CF数据结构练习
1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...
随机推荐
- 实习日记)select option 选择不同的option时, 页面发生不同的变化
怎么在下拉框的选择不同的option时, 页面发生响应的变化 因为option是没有点击事件什么的, 只有select才有, 所以不能通过option的点击事件来完成, 所以开始的尝试都失败了(之前 ...
- Django-celery分布式任务
昨天一个很好的面试官问我你在python中怎么实现定时任务呢?我没回答好,我问了下原来有个叫celery的东西,感觉挺好用的 Celery 是一个 基于python开发的分布式异步消息任务队列,通过它 ...
- Python--常用模块部分
模块 pip install #模块名称 #安装模块 #导入模块 from collections import namedtuple collections模块 提供了几个额外的数据类型: Coun ...
- Logistic Regression 笔记与理解
Logistic Regression 笔记与理解 Logistic Regression Hypothesis 记为 H(theta) H(theta)=g(z) 当中g(z),是一个叫做Logis ...
- 04 http协议模拟登陆发帖
<?php require('./http.class.php'); $http = new Http('http://home.verycd.com/cp.php?ac=pm&op=s ...
- OBS桌面视频直播软件/推流工具使用指南
OBS 操作指南 什么是OBS? Open Broadcaster Software 是一款好用的互联网流媒体直播内容输入作软件. OBS使用是否收费? 不收费,这个程序和它的源代码都是免费的. OB ...
- 点击文本选中checkbox
<checbox文本编辑/> : 只点击checkbox时,才可以选中,点击文本时无法选中 <label><checbox文本编辑/></label ...
- eclipse 中PlantUML的安装和使用
安装: 填写的地址:http://hallvard.github.io/plantuml/ 安装完plantUML后,还要下载一个Graphviz https://pan.baidu.com/s/1g ...
- Long转换为date
public static void main(String[] args) { Long time = System.currentTimeMillis(); System.out.println( ...
- jquery特效(7)—弹出遮罩层且内容居中
上周写了几个小特效,其中有个点击按钮弹出遮罩层的特效,下面来看最终实现的效果: 由于是测试的程序,所以我未加关闭的按钮. 一.主体程序 <!DOCTYPE html> <html&g ...