Codeforces Round #339 (Div. 2):( codeforces 614A codeforces 614B )


A. Link/Cut Tree

Programmer Rostislav got seriously interested in the Link/Cut Tree data structure, which is based on Splay trees. Specifically, he is now studying the expose procedure.

Unfortunately, Rostislav is unable to understand the definition of this procedure, so he decided to ask programmer Serezha to help him. Serezha agreed to help if Rostislav solves a simple task (and if he doesn't, then why would he need Splay trees anyway?)

Given integers l, r and k, you need to print all powers of number k within range from l to r inclusive. However, Rostislav doesn't want to spent time doing this, as he got interested in playing a network game called Agar with Gleb. Help him!
Input

The first line of the input contains three space-separated integers l, r and k (1 ≤ l ≤ r ≤ 1018, 2 ≤ k ≤ 109).
Output

Print all powers of number k, that lie within range from l to r in the increasing order. If there are no such numbers, print "-1" (without the quotes).
Sample test(s)
Input

1 10 2

Output

1 2 4 8

Input

2 4 5

Output

-1

Note

Note to the first sample: numbers 20 = 1, 21 = 2, 22 = 4, 23 = 8 lie within the specified range. The number 24 = 16 is greater then 10, thus it shouldn't be printed.



/*  problem:cf-614A           */
/*  author: dang              */
/*  date:   2016-1-25  22:38  */
/*  题目大意:
    k的次方数只要在区间(l,r)内就输出,如果没有输出-1.
*/
/*           ac代码        */
#include <cstdio>
#include <cstring>
int main(){
   long long  l, r, k, a = 1;
   int flag=0;
   scanf("%I64d%I64d%I64d", &l, &r, &k);
   while(a<=r){
       if(a>=l) {printf("%I64d ", a);  flag = 1;}
       if((r/a)<k) break;
       a *= k;
   }
   if(flag==0)  printf("-1\n");
    printf("\n");
   return 0;
}

<pre name="code" class="cpp">/* wa代码 不知道错哪里了。。。请指教 */
#include <cstdio>
#include <cstring>
int main(){
   long long l, r, k, a, flag=0;
   scanf("%I64d%I64d%I64d", &l, &r, &k);
   if(l==1) {
        printf("1");
        flag = 1;
   }
   a = k;
   while(k<=r){
       if(k>=l)  printf(" %I64d", k);
       if((r/k)<a) break;
       k *= a;
       flag = 1;
   }
   if(flag==0)  printf("-1\n");
    printf("\n");
   return 0;
}


 

B. Gena's Code

It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse!

There are exactly n distinct countries in the world and thei-th country added ai tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. Abeautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks ofone country was removed from the game, hence the number of tanks of this country may not remain beautiful.

Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case.

Input

The first line of the input contains the number of countries n (1 ≤ n ≤ 100 000). The second line containsn non-negative integers ai without leading zeroes — the number of tanks of thei-th country.

It is guaranteed that the second line contains at least n - 1 beautiful numbers and the total length of all these number's representations doesn't exceed100 000.

Output

Print a single number without leading zeroes — the product of the number of tanks presented by each country.

Sample test(s)
Input
3
5 10 1
Output
50
Input
4
1 1 10 11
Output
110
Input
5
0 3 1 100 1
Output
0
Note

In sample 1 numbers 10 and 1 are beautiful, number 5 is not not.

In sample 2 number 11 is not beautiful (contains two '1's), all others arebeautiful.

In sample 3 number 3 is not beautiful, all others arebeautiful.


<pre name="code" class="cpp">/*  problem:cf-614B           */
/*  author: dang              */
/*  date:   2016-1-26  10:18  */
/*  题目大意:
    有0就输出0,否则有unbeautiful数时,把这个数放在最开始,然后记录beautiful数一共有多

少0,就输出几个0,若全为beautiful数,就输出1,然后把beautiful数中的0全部输出。
 */
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n, flag = 0, num_0=0, flag_u , cnt;
    string str, ans="1";            //初始化ans为1,考虑全部都为beautiful数时的情况
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>str;
        if(str[0] == '0') {         //判断是否是0
                flag = 1;  continue;
        }
        cnt = flag_u =  0;
        for(unsigned int j = 0; j <str.length(); j ++){
            if(str[j]=='0') cnt++;               //计算0的个数
            else if(str[j]!='0'&&str[j]!='1') flag_u = 1; //判断是否有除0和1以外的数
        }
        if(flag_u||(str.length()-cnt!=1)) {    //判断是否是beautiful数
             ans = str;
        }
        else num_0 += cnt;             //若不是记录0的个数
    }
    if(flag) cout<<"0"<<endl;          //有0直接输出0
    else {
        cout<<ans;
        for(int i = 0; i < num_0; i++) cout<<"0";
        cout<<endl;
    }
    return 0;
}


 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值