Codeforces Round #324 (Div. 2)

A. Olesya and Rodion
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.

Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print  - 1.

Input

The single line contains two numbers, n and t (1 ≤ n ≤ 1002 ≤ t ≤ 10) — the length of the number and the number it should be divisible by.

Output

Print one such positive number without leading zeroes, — the answer to the problem, or  - 1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.

Sample test(s)
input
3 2
output
712

题意:找一个数满足:这个数有n位,并且能被t整除。如果找不到则输出-1
思路:纯水题,t的范围很小,只需要第一位是t然后后面的补0就可以了。因为最多是100位所以用字符串来处理即可,
注意当只有一位n=1时,t=10时找不到满足的数字。即此情况输出-1

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n, t;
	string s;
	cin >> n >> t;
	if (t == 10)
	{
		if (n == 1)
		{
			cout << -1 << endl;
		}
		else
		{
			s = 1 + '0';
			for (int i = 1; i <= n - 1; i++)
			{
				s += '0';
			}
			cout << s << endl;
		}
	}
	else
	{
		s = t + '0';
		for (int i = 1; i <= n - 1; i++)
		{
			s += '0';
		}
		cout << s << endl;
	}
	//system("pause");
	return 0;
}

B. Kolya and Tanya
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Kolya loves putting gnomes at the circle table and giving them coins, and Tanya loves studying triplets of gnomes, sitting in the vertexes of an equilateral triangle.

More formally, there are 3n gnomes sitting in a circle. Each gnome can have from 1 to 3 coins. Let's number the places in the order they occur in the circle by numbers from 0 to 3n - 1, let the gnome sitting on the i-th place have aicoins. If there is an integer i (0 ≤ i < n) such that ai + ai + n + ai + 2n ≠ 6, then Tanya is satisfied.

Count the number of ways to choose ai so that Tanya is satisfied. As there can be many ways of distributing coins, print the remainder of this number modulo 109 + 7. Two ways, a and b, are considered distinct if there is index i(0 ≤ i < 3n), such that ai ≠ bi (that is, some gnome got different number of coins in these two ways).

Input

A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three.

Output

Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo109 + 7.

Sample test(s)
input
1
output
20
input
2
output
680
Note

20 ways for n = 1 (gnome with index 0 sits on the top of the triangle, gnome 1 on the right vertex, gnome 2 on the left vertex):


题意:在圆桌上,每个人有1到3个硬币,现在从第1个人开始到3n个人依次拿出硬币只有凑起来的数满足ai + ai + n + ai + 2n ≠ 6即可,求总方法数,结果mod 109 + 7
思路:数学问题,一共有3*n个人,每个人都1 2 3的硬币 那么总的方案是为3^(3*n)等于27^n
然后再来考虑不满足要求的方法数,因为ai + ai + n + ai + 2n ≠ 6,可知3*n个人总被分成了n组,每组
相互独立,由1 2 3凑成6的方法为:2 2 2和1 2 3(1 2 3通过排列顺序可得6种加上2 2 2一共7种),每组
互相独立,通过乘法定理,n组每组为7,那么共7^n种。然后写个快速幂即可。
技巧:(a-b)%mod=(a-b+mod)%mod  这样就避免在快速幂过程中a得到的结果比b小的情况了。

#include<iostream>
using namespace std;
typedef long long int LL;
#define MOD 1000000007
LL PowerMod(LL a, LL b)//a^b
{
	LL ans = 1;
	while (b > 0)
	{
		if (b & 1)
		{
			ans = (ans*a) % MOD;
		}
		b >>= 1;
		a = (a*a) % MOD;
	}
	return ans;
}
int main()
{
	int n;
	cin >> n;
	cout << (PowerMod(27, n) - PowerMod(7, n) + MOD) % MOD << endl;
	//system("pause");
	return 0;
}

D. Dima and Lisa
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.

More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that

  1. 1 ≤ k ≤ 3
  2. pi is a prime

The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

Input

The single line contains an odd number n (3 ≤ n < 109).

Output

In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.

In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.

Sample test(s)
input
27
output
3
5 11 11
Note

A prime is an integer strictly larger than one that is divisible only by one and by itself.


题意:对于n找出k个数(1<=k<=3)满足,这k个数是素数并且k个数相加的和为n。输出最小的k和这k个素数,若有多种答案只需输出任意一组
思路:暴力。从第一个开始找。如果n本身就是素数那么答案就是n本身,否则找到离n最近的素数,然后把问题的n转换为n-离n最近的素数,第三
个也是如此。
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<cmath>
using namespace std;  
int p[8] = { 4, 2, 4, 2, 4, 6, 2, 6 };
bool prime(int n)
{
	int i = 7, j, q;
	if (n == 1)
	{
		return false;
	}
	if (n == 2 || n == 5 || n == 3)
	{
		return true;
	}
	if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0)
	{
		return false;
	}
	q = sqrt(n*1.0);
	for ( ; i <= q; )
	{
		for (j = 0; j<8; j++)
		{
			if (n%i == 0)
			{
				return false;
			}
			i += p[j];
		}
		if (n%i == 0)
		{
			return false;
		}
	}
	return true;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=n;i>=2;i--)
	{
		if(prime(i))
		{
			if(i==n)
			{
				printf("1\n");
				printf("%d\n",i);
				return 0;
			}
			for(int j=n-i;j>=2;j--)
			{
				if(prime(j))
				{
					if(i+j==n)
					{
						printf("2\n");
						printf("%d %d\n",i,j);
						return 0;
					}
					if(prime(n-i-j))
					{
						printf("3\n");
						printf("%d %d %d\n",i,j,n-i-j);
						return 0;
					}
				}
			}
		}
	}
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值