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的数取 ...
随机推荐
- CSS3中的动画效果-------Day72
还记得么,在前面也曾实现过"仅仅用css让div动起来",还记得当时是怎么实现的么,是的,transition,针对的也比較局限,仅仅有旋转角度啊,长宽啊之类的,所以说,与其说是动 ...
- Twitter网站架构分析介绍
http://www.kaiyuanba.cn/html/1/131/147/7539.htm作为140个字的缔造者,twitter太简单了,又太复杂了,简单是因为仅仅用140个字居然使有几次世界性事 ...
- python去除停用词(结巴分词下)
python 去除停用词 结巴分词 import jieba #stopwords = {}.fromkeys([ line.rstrip() for line in open('stopword. ...
- android等待旋转圆圈动画
先创建一个动画的xml文件例如以下 <? xml version="1.0" encoding="utf-8"?> <animation-li ...
- How to reset your password in Ubuntu
There are many reasons you might want to reset a password: Someone gave you a computer with Ubuntu i ...
- 关于0基础磁盘管理(gpt UEFI...)最好的一篇文章(来自gentoo linux)
放链接:https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Disks 顺便几张图 watermark/2/text/aHR0cDovL2 ...
- 多媒体开发之编码gop---什么是GOP
所谓GOP,意思是画面组,MPEG格中的帧序列,分为I.P.B三种,如排成IBBPBBPBBPBBPBBP...样式,这种连续的帧图片组合即为GOP(画面群,GROUP OF PICTURE),是MP ...
- 2018.11.20-day22 类中代码的执行顺序&组合
1.类中代码的执行顺序 2.组合
- Collection of Boot Sector Formats for ISO 9660 Images
http://bazaar.launchpad.net/~libburnia-team/libisofs/scdbackup/view/head:/doc/boot_sectors.txt Colle ...
- 面向资源操作的http请求
Guide | Echo - High performance, minimalist Go web framework https://echo.labstack.com/guide e.POST( ...