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的数取 ...
随机推荐
- Android Volley分析(一)——结构
Volley是Android系统下的一个网络通信库.为Android提供简单高速的网络操作(Volley:Esay, Fast Networking for Android),以下是它的结构: 既然是 ...
- 实习日记)select option 选择不同的option时, 页面发生不同的变化
怎么在下拉框的选择不同的option时, 页面发生响应的变化 因为option是没有点击事件什么的, 只有select才有, 所以不能通过option的点击事件来完成, 所以开始的尝试都失败了(之前 ...
- mini2440使用jlink烧写superboot到norflash
Jlink版本号:J-flash ARM V4.12 J-Flash ARM的配置. 一般说来file-->open project里面会找到一些*.jfl ...
- IDA断点和搜索
一.断点 调试很重要一点是下断点,看看IDA提供的功能,本来已经和WinDbg一样强了. 官方文档的变化 Edit breakpoint Action name: BreakpointEdit Con ...
- PHP魔术方法之__call与__callStatic方法
<?php class human{ private function t(){ } //魔术方法__call /* $method 获得方法名 $arg 获得方法的参数集合 */ public ...
- Mac OS command line TestNG - “Cannot find class in classpath” error
直接eclipse执行.xml文件可以正确执行 在mac下执行却总报错: [TestNG] [Error] Cannot find class in classpath 最后解决办法,classpat ...
- git 安装及命令
一.window下的git安装 1.安装教程 网上教程一堆.我參考的是这个:Git_Windows 系统下Git安装图解 还有这个也不错 2.环境搭建: 在配置完毕后,自己主动载入到系统环境变量中.如 ...
- gcc參数总结
/*gcc 命令总结*/ 补充下gcc的知识,免得被大自然说编译原理不行.. 1.-o 參数 參数说明: -o參数用来指定生成程序的名字 gcc test.c 会编译出一个名为a.out的程序 gcc ...
- Android Eclipse 导入 AS Gradle AAR 库手冊
序言 这是一篇半技术类文章.众所周知如今Google主推Android Studio开发工具.而Eclipse已经被闲置一阵子了,可是Eclipse项目却还有非常多没有迁移到AS中.而如今一些新的库都 ...
- JQGrid总记录数和查询消耗时间不显示
其他做的几个页面都显示,只有一个不显示....百度发现, viewrecords选项未配置,应该设置为ture才可以.