cf Perfect Pair

本文提供了一种解决CodeForces竞赛中318C问题的方法,通过循环迭代更新两个变量的值直至满足题目条件。该算法考虑了输入数值可能为负数的情况,并确保最终结果的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://codeforces.com/contest/318/problem/C

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 using namespace std;
 5 long long j;
 6 long long x,y,m;
 7 int main()
 8 {
 9     scanf("%I64d%I64d%I64d",&x,&y,&m);
10     if(x>=m||y>=m)
11     {
12         printf("0\n");
13         return 0;
14     }
15     else if(x<=0&&y<=0)
16     {
17         printf("-1\n");
18         return 0;
19     }
20     if(x<0)
21     {
22         j=(-x)/y+1;
23         x+=j*y;
24     }
25     if(y<0)
26     {
27         j=(-y)/x+1;
28         y+=j*x;
29     }
30     while(1)
31     {
32         if(!(x<m&&y<m)) break;
33         if(x>y) y=x+y;
34         else x=x+y;
35         j++;
36     }
37     printf("%I64d\n",j);
38     return 0;
39 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3667410.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值