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.
The single line contains two numbers, n and t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10) — the length of the number and the number it should be divisible by.
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.
#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;
}
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).
A single line contains number n (1 ≤ n ≤ 105) — the number of the gnomes divided by three.
Print a single number — the remainder of the number of variants of distributing coins that satisfy Tanya modulo109 + 7.
1
20
2
680
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):
#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;
}
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 ≤ k ≤ 3
- pi is a prime
The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
The single line contains an odd number n (3 ≤ n < 109).
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.
27
3 5 11 11
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个素数,若有多种答案只需输出任意一组
#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;
}
}
}
}
}
}