ACDream 1408 "Money, Money, Money" (规律)

探讨了如何选择两种面额的钞票,以便能够支付所有大于特定数值x的金额,但不能恰好支付x元。分析表明,当x为奇数时,可以通过2和x+2来组成所有大于x的数字;而x为偶数时,则无法找到解决方案。

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

"Money, Money, Money"

Special Judge Time Limit: 2000/1000MS (Java/Others)
 Memory Limit: 128000/64000KB (Java/Others)
Problem Description
      The government of Flatland has decided to carry out the money system reform. The purpose of the reform is to reduce the number of different banknotes denominations down to two. After the reform there will be two types of banknotes — a tupiks and b tupiks.
      The problem is that the president of Flatland doesn’t like the number x. Therefore the minister of finances was instructed to choose such a and b that it is impossible to pay exactly x tupiks without change. On the other hand it must be possible to pay all amounts larger than x.
      Now you are asked to help him — choose such a and b, or recommend the minister to retire, if it is impossible.
Input
      Input file contains one number x (1 ≤ x ≤ 1012).
Output
      Output two integer numbers a and b, such that it is impossible to pay x tupiks using banknotes of a and b tupiks without change, but it is possible to pay any larger sum. If it is impossible, output two zeroes to the output file.
Sample Input
3
4
5
Sample Output
2 5
0 0
3 4
Source
Andrew Stankevich Contest 21
 
题意:找到两个数,使得其能够组成大于x的所有数字
分析:这道题如果x是偶数,小数据模拟了一下发现是无解的,x是奇数的话那么大于x的数字可以由2和x+2组成。
至于为什么x是偶数时是无解还是没有推出来,过往大牛看到解答一下~
#pragma comprint(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<stdlib.h>
#include<time.h>
#include<algorithm>
#define LL long long
#define FIN freopen("in.txt","r",stdin)
using namespace std;
int main()
{
    LL x;
    while(scanf("%lld",&x)!=EOF)
    {
        if(x&1)
            printf("2 %lld\n",x+2);
        else
            printf("0 0\n");
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/clliff/p/4761905.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值