Equation
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Let’s call a positive integer composite if it has at least one divisor other than 1 and itself. For example:
the following numbers are composite: 1024, 4, 6, 9;
the following numbers are not composite: 13, 1, 2, 3, 37.
You are given a positive integer n. Find two composite integers a,b such that a−b=n.
It can be proven that solution always exists.
Input
The input contains one integer n (1≤n≤107): the given integer.
Output
Print two composite integers a,b (2≤a,b≤109,a−b=n).
It can be proven, that solution always exists.
If there are several possible solutions, you can print any.
Examples
input
1
output
9 8
input
512
output
4608 4096
最朴素的无脑做法,就是判断是不是素数,还有i-n是不是素数,一个个找
#include
using namespace std;
typedef long long ll;
int prime(int a)
{
if(a<=1)
return 0;
for(int i=2;i<=sqrt(a);i++)
if(i!=a&&a%i==0)
return 0;
return 1;
}
void hzh()
{
ll n;
scanf("%lld",&n);
for(ll i=n+2;;i++)
{
if(prime(i)==0&&prime(i-n)==0)
{
printf("%lld %lld",i,i-n);
return;
}
}
}
int main()
{
/*
int t;
scanf("%d",&t);
while(t--)
*/
hzh();
return 0;
}
Modulo Equality
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a positive integer m and two integer sequence: a=[a1,a2,…,an] and b=[b1,b2,…,bn]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3].
You need to find the non-negative integer x, and increase all elements of ai by x, modulo m (i.e. you want to change ai to (ai+x)modm), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x.
In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p1,p2,…,pn], such that for all 1≤i≤n, (ai+x)modm=bpi, where ymodm — remainder of division of y by m.
For example, if m=3, a=[0,0,2,1],b=[2,0,1,1], you can choose x=1, and a will be equal to [1,1,0,2] and you can rearrange it to make it equal [2,0,1,1], which is equal to b.
Input
The first line contains two integers n,m (1≤n≤2000,1≤m≤109): number of elemens in arrays and m.
The second line contains n integers a1,a2,…,an (0≤ai The third line contains n integers b1,b2,…,bn (0≤bi It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p1,p2,…,pn such that (ai+x)modm=bpi. Output Examples 这题的主要思路就是暴力,不过不是暴力x,而是暴力a[0]对应b中的哪个元素,时间复杂度o(n) *Long Beautiful Integer Also, you are given a positive integer k Let’s call integer b1,b2,…,bm beautiful if bi=bi+k for each i, such that 1≤i≤m−k. You need to find the smallest beautiful integer y, such that y≥x. Input The next line of input contains n digits a1,a2,…,an (a1≠0, 0≤ai≤9): digits of x. Output In the next line print m digits b1,b2,…,bm (b1≠0, 0≤bi≤9): digits of y. Examples 又是一道巨坑题,坑点特别特别多 D. Domino for Young Given diagram is a histogram with n columns of lengths a1,a2,…,an (a1≥a2≥…≥an≥1). Young diagram for a=[3,2,2,2,1]. Input The next line of input contains n integers a1,a2,…,an (1≤ai≤300000,ai≥ai+1): the lengths of columns. Output Example 如果an是偶数,直接就可以放an/2块;麻烦的是如果an是奇数的情况。
Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p1,p2,…,pn such that (ai+x)modm=bpi for all 1≤i≤n.
input
4 3
0 0 2 1
2 0 1 1
output
1
input
3 2
0 0 0
1 1 1
output
1
input
5 10
0 0 0 1 2
2 1 0 0 0
output
0
但这题有一个巨坑的点,就是数组大小开2001过不去!!!开到2003就过去了,醉了。#include
C
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given an integer x of n digits a1,a2,…,an, which make up its decimal notation in order from left to right.
The first line of input contains two integers n,k (2≤n≤200000,1≤k
In the first line print one integer m: the number of digits in y.
input
3 2
353
output
3
353
input
4 2
1234
output
4
1313
我的思路是:确定前m个元素,然后循环打印,打完为止
(我至今没想明白,为啥题目要求我们打一遍n,完全没有意义)
从第j=m+1个元素开始,去和它对应的j%m个元素对比大小。这里特别注意,因为我是从1开始读的,所以j%m的值可能为0,而我实际上想对比的是第m个元素,因此我用了个特判。
如果这个元素比他对应的元素大,那么单纯循环打印m个元素的值会比原值小,所以让第m个元素+1,那么循环打印的数一定比原数要大,但如果第m个元素为9,那么就要考虑进位。
如果这个元素比他对应的元素小,那么就直接循环打印。
如果这个元素比他对应的元素一样大,那么就判断下一个。#include
D
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
You are given a Young diagram.
Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1×2 or 2×1 rectangle.
The first line of input contain one integer n (1≤n≤300000): the number of columns in the given histogram.
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.
inputCopy
5
3 2 2 2 1
outputCopy
4
如果两个长度为奇数的列靠在一起,就可以在an/2的基础上再多一块,
靠在一起,距离为0,可以推得距离为偶数的时候,结论仍成立
也就是说:
如果n为奇数的长度为奇数的列有x个,如果n为偶数的长度为奇数的列有y个,那么可以多min(x,y)块。#include