codeforce #762 div3

A. Square String?

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square.

For a given string ss determine if it is square.

Input

The first line of input data contains an integer tt (1≤t≤1001≤t≤100) —the number of test cases.

This is followed by tt lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between 11 and 100100 inclusive.

Output

For each test case, output on a separate line:

  • YES if the string in the corresponding test case is square,
  • NO otherwise.

You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response).

input:

10
a
aa
aaa
aaaa
abab
abcabc
abacaba
xxyy
xyyx
xyxy
 

output:

NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char str[110];
int main(){
	int t,ll,i,flag=0;
	scanf("%d",&t);
	getchar();
	while(t--){
		flag=0;
		gets(str+1);
		ll = strlen(str+1);
		if(ll%2!=0){
			printf("NO\n");
			continue;
		}
		else{
			for(i=1;i<=ll/2;i++){
				if(str[i]!=str[i+ll/2]){
					flag=1;
					printf("NO\n");
					break;
				}
			}
			if(flag==0){
				printf("YES\n");
			}
		}
	}
	return 0;
}

B. Squares and Cubes

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Polycarp likes squares and cubes of positive integers. Here is the beginning of the sequence of numbers he likes: 11, 44, 88, 99, ....

For a given number nn, count the number of integers from 11 to nn that Polycarp likes. In other words, find the number of such xx that xx is a square of a positive integer number or a cube of a positive integer number (or both a square and a cube simultaneously).

Input

The first line contains an integer tt (1≤t≤201≤t≤20) — the number of test cases.

Then tt lines contain the test cases, one per line. Each of the lines contains one integer nn (1≤n≤1091≤n≤109).

Output

For each test case, print the answer you are looking for — the number of integers from 11 to nn that Polycarp likes.

input:

6
10
1
25
1000000000
999999999
500000000
 

output:

4
1
6
32591
32590
23125
 

#include <stdio.h>
int t,sum;
int main(){
	double n;
	scanf("%d",&t);
	while(t--){
		scanf("%lf",&n);
		n += (0.00001);
		sum=(int)(pow(n,1.0/2))+(int)(pow(n,1.0/3))-(int)(pow(n,1.0/6));
		printf("%d\n",sum);
	}
}

C. Wrong Addition

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Tanya is learning how to add numbers, but so far she is not doing it correctly. She is adding two numbers aa and bb using the following algorithm:

  1. If one of the numbers is shorter than the other, Tanya adds leading zeros so that the numbers are the same length.
  2. The numbers are processed from right to left (that is, from the least significant digits to the most significant).
  3. In the first step, she adds the last digit of aa to the last digit of bb and writes their sum in the answer.
  4. At each next step, she performs the same operation on each pair of digits in the same place and writes the result to the left side of the answer.

For example, the numbers a=17236a=17236 and b=3465b=3465 Tanya adds up as follows:

+17236034651106911+17236034651106911

  • calculates the sum of 6+5=116+5=11 and writes 1111 in the answer.
  • calculates the sum of 3+6=93+6=9 and writes the result to the left side of the answer to get 911911.
  • calculates the sum of 2+4=62+4=6 and writes the result to the left side of the answer to get 69116911.
  • calculates the sum of 7+3=107+3=10, and writes the result to the left side of the answer to get 106911106911.
  • calculates the sum of 1+0=11+0=1 and writes the result to the left side of the answer and get 11069111106911.

As a result, she gets 11069111106911.

You are given two positive integers aa and ss. Find the number bb such that by adding aa and bb as described above, Tanya will get ss. Or determine that no suitable bb exists.

Input

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

Each test case consists of a single line containing two positive integers aa and ss (1≤a<s≤10181≤a<s≤1018) separated by a space.

Output

For each test case print the answer on a separate line.

If the solution exists, print a single positive integer bb. The answer must be written without leading zeros. If multiple answers exist, print any of them.

If no suitable number bb exists, output -1.

input

6
17236 1106911
1 5
108 112
12345 1023412
1 11
1 20
 

output

3465
4
-1
90007
10
-1
 

#include <stdio.h>
#include <stdlib.h>
int t;
int b[20];
char a[20],s[20];
int main(){
	int la,ls,i,j,k=0,flag=1;
	scanf("%d",&t);
	getchar();
	while(t--){
		flag = 1;
		k=0;
		scanf("%s %s",a,s);
		la = strlen(a);
		ls = strlen(s);
		i = la - 1 ; j = ls - 1;
		while(i>=0){
			if(a[i]-s[j]>0){
				if(s[j-1]!='1'){
					flag = 0;
					break;
				}
				else{
					b[k] = s[j]-a[i] + 10;
					k++;j-=2;i--;
				}
			}
			else if(s[j]-a[i]>=0){
				b[k] = s[j] - a[i];
				k++;j--;i--;
			}
			else if(j<0&&i>=0){
				flag = 0;
				break;
			}
		}
		k-=1;
		//输出
		if(flag == 0){
			printf("-1\n");
		} 
		else{
			if(j==-1){
				while(b[k]==0){
					k--;
				}
				for(k;k>=0;k--){
					printf("%d",b[k]);
				}
				printf("\n");
			}
			else{
				for(i = 0;i<=j;i++){
					printf("%c",s[i]);
				} 
				for(k;k>=0;k--){
					printf("%d",b[k]); 
				}printf("\n");
			}
		}
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值