ACdream 1408 "Money, Money, Money"(找规律)

"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 ≤ 10 12).
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

题目大意:

给出一个数x,输出两个数a,b,要求任意个a与任意个b不能组合出x,但能组合出x之后的所有正整数(多种答案只要输出任意一种)。

解题思路:
题目看上去很难→_→。
当x是偶数时,找不到a和b满足题意;
当x是奇数时,我们要找到a和b使得它们能组成任何大于x的正整数。由于这些正整数中有奇数有偶数,所以一定要挑出一个2,因为2能组成所有的正偶数,然后再选出x+2即可,因为x是奇数,x+1一定是偶数,可以由2组成,x+2不能由2组成,所以必须挑出x+2。这样就可以使得x以后的所有偶数都由2组成,所有奇数的由x+2和若干个2组成。


参考代码:

#include <cstdio>
int main()
{
    long long x;
    while(~scanf("%lld",&x))
    {
        if(x&1) printf("2 %lld\n",x+2);
        else printf("0 0\n");
    }
    return 0;
}


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值