C Looooops POJ - 2115 (exgcd)
for(int i=A;i!=B;i+=C)
内容;
其中所有数都是k位二进制数,即所有数时膜2^k意义下的。我们的目标时球出 内容 被执行了多少次。
Input
Output
Sample Input
1 3 2 4
1 5 2 4
1 2 4 3
0 0 0 0
Sample Output
1
2
FOREVER 这和青蛙的那个题是一样的 想象成跑圈
写出式子 就可以了
注意最后对x的处理
ax + by = c
最后 b /= d;
x = (x % b + b) % b;
输出x即可
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = , INF = 0x7fffffff; LL gcd(LL a, LL b)
{
return b == ? a : gcd(b, a % b);
} LL exgcd(LL a, LL b, LL& d, LL& x, LL& y)
{
if(!b)
{
d = a;
x = ;
y = ;
}
else
{
exgcd(b, a % b, d, y, x);
y -= x * (a / b);
}
} int main()
{
LL a, b, c, k, x, y, d;
while(cin >> a >> b >> c >> k)
{
if(a == && b == && c == && k == )
break;
LL s = 1LL << k;
if((b - a) % gcd(c, s))
{
cout << "FOREVER" << endl;
continue;
}
exgcd(c, s, d, x, y);
s /= d;
x *= (b - a) / d;
x = (x % s + s) % s;
cout << x << endl;
} return ;
}
C Looooops POJ - 2115 (exgcd)的更多相关文章
- B - C Looooops POJ - 2115 (扩展欧几里得)
		题目链接:https://cn.vjudge.net/contest/276376#problem/B 题目大意:for( int i= A ; i != B; i+ = c ),然后给你A,B,C ... 
- 青蛙的约会 POJ - 1061 (exgcd)
		两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面.它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止.可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特 ... 
- 扩展欧几里得算法(EXGCD)学习笔记
		0.前言 相信大家对于欧几里得算法都已经很熟悉了.再学习数论的过程中,我们会用到扩展欧几里得算法(exgcd),大家一定也了解过.这是本蒟蒻在学习扩展欧几里得算法过程中的思考与探索过程. 1.Bézo ... 
- 【题解】POJ 2115 C Looooops (Exgcd)
		POJ 2115:http://poj.org/problem?id=2115 思路 设循环T次 则要满足A≡(B+CT)(mod 2k) 可得 A=B+CT+m*2k 移项得C*T+2k*m=B-A ... 
- C Looooops POJ - 2115    拓展gcd  有一个定理待补()
		补算法导论P564 MODULAR-LINEAR-EQUATION-SOLVER算法(P564) 
- POJ题目(转)
		http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法: (1)枚举. (poj1753,poj29 ... 
- E - The Balance POJ - 2142  (欧几里德)
		题意:有两种砝码m1, m2和一个物体G,m1的个数x1, m2的个数为x2, 问令x1+x2最小,并且将天平保持平衡 !输出 x1 和 x2 题解:这是欧几里德拓展的一个应用,欧几里德求不定方程 ... 
- 欧几里得(辗转相除gcd)、扩欧(exgcd)、中国剩余定理(crt)、扩展中国剩余定理(excrt)简要介绍
		1.欧几里得算法(辗转相除法) 直接上gcd和lcm代码. int gcd(int x,int y){ ?x:gcd(y,x%y); } int lcm(int x,int y){ return x* ... 
- Repeater POJ - 3768 (分形)
		Repeater POJ - 3768 Harmony is indispensible in our daily life and no one can live without it----may ... 
随机推荐
- 关于getHibernateTemplate().get()方法
			返回的对象值唯一,方法带有两个参数 第一个是意图查询实体的Class 如User.Class ;第二个参数是该实体在数据库中对应的主键值,而且参数的类型要和映射文件相对应. 如 Role role ... 
- Python学习第十一篇——for 的本质及如何正确修改列表
			假如现在有一个列表:magicians_list = ['mole','jack','lucy'],现在想通过一个函数来实现,在列表的每个元素前面加上“the Great”的字样.现在通过一个函数来实 ... 
- NFV论文集(二)
			一 文章名称:VNF Placement with Replication for Load Balancing in NFV Networks 发表时间:2017 期刊来源:ICC: IEEE In ... 
- spring security运行流程图(转)
			原文:http://blog.csdn.net/u011511684/article/details/31394493 示例下载地址:http://download.csdn.net/detail/u ... 
- Windows之文件夹中打开PowerShell
			Windows之文件夹中打开PowerShell 为了解决Windows中在某个路径下使用PowerShell,而不是使用传统的cd命令切换过去,具体做法如下: 方法一 打开文件夹 在文件夹的内容区按 ... 
- Linux sudoers
			xxx is not in the sudoers file.This incident will be reported.的解决方法 - xiaochaoyxc - 博客园http://www.cn ... 
- python3 打开页面后多窗口处理三种方法
			多窗口处理三种方法 导包,实例化浏览器from selenium import webdriver fx=webdriver.Firefox()方法一fx.switch_to.window(fx.wi ... 
- java 工具
			JClassLib 4.2 发布了,该版本支持 Java 7 和 Java 8 的类文件属性查看. JClassLib不但是一个字节码阅读器而且还包含一个类库允许开发者读取,修改,写入Java Cla ... 
- C#设计模式之9:模板方法
			模板方法 模板方法是一个方法,定义了算法的步骤,并允许子类为一个或多个步骤提供实现. 本例中用冲泡咖啡和茶的例子来说明: 上图说明了冲泡咖啡和茶的步骤,可以看出冲泡咖啡和茶的步骤差不多,很相似,先来看 ... 
- JavaScript中的函数和C#中的匿名函数(委托、lambda表达式)
			在js中function是一个一个引用类型,所以可以出现这样的代码: 'use strict'; var compare=function(value1, value2) { if (value1&l ... 
