Giúp làm bài tập lập trình

bác nào giúp e với

Help me!!!
I want code...help me please!!!


Problem B: Mysterious Treasure
The planet of Nine Dragons is famous not only for its beautiful scene but also for the legend about the
secret treasures. As an astronaut, you have found an old map guiding you to the secret cave where the
treasures are hidden. Unfortunately, the door of the cave is locked and is only opened at certain times of
the day.
A day in this planet is very long as it has 10
9
minutes. The door of the cave is opened at the n
th
minutes
(from midnight) if n! = 1 ×2 ×… nis divisible by n
3
(i.e., n! mod n
3
= 0).
Given n, your task is to write a program to determine if the door of the cave is opened at the n
th
minute.
Input
The input file consists of several data sets. The first line of the input file contains the number of data
sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
Each data set consists of one line containing the integer n(1< n< 10
9
).
Output
For each data set write in one line “YES” if the door is opened at the given n
th
minute or “NO”
otherwise.
Sample Input Sample Output
2
6
12
NO
YES








Problem C: Prime Concatenation
Given two positive integers nand d, your task is to write a program to find the smallest positive integer
mwith at least 2ddigits, satisfying the following conditions:
• m≥ n
• mis a concatenation of two prime numbers, each number has at least ddigits.
For example, given d= 2, n= 1112, then the smallest mis 1113 which is the concatenation of two 2-digit primes 11 and 13.
Input
The input file consists of several data sets. The first line of the input file contains the number of data
sets which is a positive integer and is not bigger than 20. The following lines describe the data sets.
Each data set consists of one line containing two space-separated positive integers nand d(1≤ n≤ 10
9
và 1 ≤ d≤ 5).
Output
For each data set write in one line the desired number m.
Sample Input Sample Output
3
1112 2 1113
10 1 22
2011 2 2311
 

taplamhacker

♥ Thanh Trâm ♥
Reply: giúp em với

:nherang:
bạn có thể cho mình xin cái link đề được k @@ bạn copy hình như sai đó
 

taplamhacker

♥ Thanh Trâm ♥
:nherang: bạn copy cái câu 1 bị ngáo rồi @@
cho mình xin link với
đọc dc câu 2 à
câu 2 của bạn đây :haha:
số mình gán đại cho nhanh
bạn tùy biến theo yêu cầu của đề nha
CODE
[AH]
Mã:
#include<stdio.h>
#include<math.h>
int demchuso(int n)
{
	int dem = 0;
	while(n>0)
	{
		n /= 10;
		dem++;
	}
	return dem;
}
int snt(int n)
{
	if(n < 2)
		return 0;
	if(n == 2 || n == 3)
		return 1;
	if(n % 2 == 0 || n % 3 == 0)
		return 0;
	for(int i = 5 ; i <= sqrt(n) ; i += 2)
		if(n % i == 0)
			return 0;
	return 1;	
	
}
int ghep(int n, int m)
{
	int tmp = demchuso(n);
	switch(tmp)
	{
		case 1:
			return n*10+m;
		case 2:
			return n*100+m;
		case 3:
			return n*1000+m;
		case 4:
			return n*10000+m;
		case 5:
			return n*100000+m;
		case 0:
			return 0; 
	}
}
int main()
{
	int d = 2;
	int n = 2011;
	int i = 0, j = 0;
	int kq = 0;
	while(1)
	{
		j = 0;
		if( snt(i) == 1 && demchuso(i) == d)
			while(1)
			{
				if(demchuso(j) == d && snt(j) == 1 )
				{
					kq = ghep(i,j);
					if(kq > n)
						break;
				}
				if(demchuso(j) > d)
					break;
				j++;
			} 
		if(demchuso(i) > d  || kq > n)
			break;
		i++;
	}
	printf("%d",kq);
}
[/AH]
 

quanltv

Sư phụ của ADMIN
Thớt nói đúng 1 câu tiếng Việt, đề thì ghi tiếng Anh, làm bằng mắt à :troll:
 
sr các bạn đã tốn time giúp mình nha mình dịch được bài số 2 tức là cánh cửa sẽ mở vào giây thứ n khi n! chia hết cho n^3 tức là giờ làm sao viết được hàm kiểm tra 1 số nguyên dương n nếu n! chia hết cho n^3 cout<<yes else cout<<no vậy đấy ạ
 
bài n! chia n mũ 3 đó mình biết là dùng mảng và phải phân tích ra thừa số nguyên tố rồi nhưng ko biết kiểm tra thế nào thì là chia hết vì n rất lớn nên ko thể làm kiểu binh thường được các bạn giúp mình nhé cám ơn
 
bài này submit lên kiểm tra thử bị time limit rồi quá thời gian vì n <= 10 mũ 9 bạn ơi bạn code lại theo thư viện iostream đc không cách của bạn đúng với số nhỏ thôi tks bạn nhiều
 

Thống kê

Chủ đề
100,746
Bài viết
467,576
Thành viên
339,851
Thành viên mới nhất
Đông Âu
Top