[洛谷]CF1660A Vasya and Coins

Vasya decided to go to the grocery store. He found in his wallet aa coins of 11 burle and bb coins of 22 burles. He does not yet know the total cost of all goods, so help him find out ss (s>0s>0): the minimum positive integer amount of money he cannot pay without change or pay at all using only his coins.

For example, if a=1a=1 and b=1b=1 (he has one 11-burle coin and one 22-burle coin), then:

  • he can pay 11 burle without change, paying with one 11-burle coin,
  • he can pay 22 burle without change, paying with one 22-burle coin,
  • he can pay 33 burle without change by paying with one 11-burle coin and one 22-burle coin,
  • he cannot pay 44 burle without change (moreover, he cannot pay this amount at all).

So for a=1a=1 and b=1b=1 the answer is s=4s=4.

Input

The first line of the input contains an integer tt (1≤t≤1041≤t≤104) — the number of test cases in the test.

The description of each test case consists of one line containing two integers aiai and bibi (0≤ai,bi≤1080≤ai,bi≤108) — the number of 11-burle coins and 22-burles coins Vasya has respectively.

Output

For each test case, on a separate line print one integer ss (s>0s>0): the minimum positive integer amount of money that Vasya cannot pay without change or pay at all.

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(a==0)printf("1\n");
        else printf("%d\n",2*b+a+1);
    }
    return 0;
}

大概就是分两种情况,一种是有1元的硬币,那么得到的最大值就是总面额+1,另一种则没有1元硬币,这个时候面值为1也没办法完成

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值