博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2115:C Looooops
阅读量:6544 次
发布时间:2019-06-24

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

C Looooops
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 19536   Accepted: 5204

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 163 7 2 167 3 2 163 4 2 160 0 0 0

Sample Output

0232766FOREVER

题意是问在

for (variable = A; variable != B; variable += C)

这样的情况下,循环多少次。

当中全部的数要mod 2的k次方。所以方程就是(A+C*x)%(2^k)=B,变换一下就是-C*x+(2^k)*y=A-B。解这个方程的最小正数x就可以。

又是扩展欧几里德。

代码:

#include 
#include
#include
#include
#include
using namespace std;long long yue;void ex_gcd(long long a,long long b, long long &xx,long long &yy){ if(b==0) { xx=1; yy=0; yue=a; } else { ex_gcd(b,a%b,xx,yy); long long t=xx; xx=yy; yy=t-(a/b)*yy; }}int main(){ long long A,B,C,k,k2,xx,yy; while(scanf_s("%lld%lld%lld%lld",&A,&B,&C,&k)) { if(!A&&!B&&!C&&!k) break; k2=(1LL<

转载地址:http://ieodo.baihongyu.com/

你可能感兴趣的文章
jenkins 忘记admin用户账号密码
查看>>
N++ 道ASP.NET面试题
查看>>
在 Java 中使用启发式搜索更快地解决问题
查看>>
转:windows下多线程通信方法
查看>>
C# 实现将 PDF 转文本的功能
查看>>
android导航设计
查看>>
spm中头动绘图的理解,自带数据集
查看>>
Java的深度克隆和浅度克隆
查看>>
Nodejs学习笔记(二)--- 事件模块
查看>>
HDUOJ------2398Savings Account
查看>>
script标签块的独立性与共享性
查看>>
SpringMVC轻松学习-其他常用(四)
查看>>
LDAP缓存命令
查看>>
〖Android〗Android源代码所有目录生成的Target(编译生成文件反查)
查看>>
iOS开发UI篇—Quartz2D使用(绘图路径)
查看>>
[再寄小读者之数学篇](2014-06-14 [四川师范大学 2014 年数学分析考研试题] 积分不等式)...
查看>>
lucene 过滤结果
查看>>
第26周六悲剧许昌夜
查看>>
ASP.NET并发处理
查看>>
atitit.提升开发效率---mda 软件开发方式的革命--(2)
查看>>