博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C Looooops 同余方程(扩展欧几里得算法)
阅读量:6223 次
发布时间:2019-06-21

本文共 1865 字,大约阅读时间需要 6 分钟。

Problem Description
A Compiler Mystery: We are given a C-language style for loop of type 
for (variable = A; variable != B; variable += C)   statement;
I.e., a loop which starts by setting variable to value A and while variable is not equal to B, repeats statement followed by increasing the variable by C. We want to know how many times does the statement get executed for particular values of A, B and C, assuming that all arithmetics is calculated in a k-bit unsigned integer type (with values 0 <= x < 2
k) modulo 2
k
 

Input
The input consists of several instances. Each instance is described by a single line with four integers A, B, C, k separated by a single space. The integer k (1 <= k <= 32) is the number of bits of the control variable of the loop and A, B, C (0 <= A, B, C < 2
k) are the parameters of the loop. 
The input is finished by a line containing four zeros. 
 

Output
The output consists of several lines corresponding to the instances on the input. The i-th line contains either the number of executions of the statement in the i-th instance (a single integer number) or the word FOREVER if the loop does not terminate. 
 

Sample Input
3 3 2 16 3 7 2 16 7 3 2 16 3 4 2 16 0 0 0 0
 

Sample Output
0 2 32766 FOREVER
***************************************************************************************************************************
***************************************************************************************************************************
ContractedBlock.gif
ExpandedBlockStart.gif
1 #include
2 #include
3 #include
4 #include
5 #include
6 using namespace std; 7 typedef __int64 LL; 8 LL A,B,C,k; 9 //欧几里得算法10 LL gcd(LL a,LL b)11 {12 LL c;13 if(a
View Code

转载于:https://www.cnblogs.com/sdau--codeants/p/3381808.html

你可能感兴趣的文章
Linux基础(day44)
查看>>
Git 分支创建及使用
查看>>
MariaDB安装, Apache安装
查看>>
多线程三分钟就可以入个门了!
查看>>
从道法术三个层面理解区块链:术
查看>>
elasticsearch入门使用
查看>>
数据结构与算法4
查看>>
tomcat去掉项目名称
查看>>
微服务架构的优势与不足(一)
查看>>
分布式服务治理框架Dubbo
查看>>
小程序好的ui框架选择
查看>>
今天学习了
查看>>
Tomcat安装、配置、优化及负载均衡详解
查看>>
虹软人脸识别SDK(java+linux/window) 初试
查看>>
ppwjs之bootstrap文字排版:到标题元素
查看>>
为了解「鼠语」华盛顿大学开发DeepSqueak深度学习软件
查看>>
jQuery-ajax
查看>>
Xcode WorkSpace含静态库多项目依赖编译
查看>>
jQueryTimers
查看>>
#奇思妙想#头脑风暴馆
查看>>