Số đẹp tăng giảm
Đề bài:
Một số được gọi là số tăng giảm nếu số đó có các chữ số thỏa mãn hoặc tăng dần, hoặc giảm dần từ trái qua phải.
Hãy đếm các số nguyên tố là số tăng giảm với số chữ số cho trước
INPUT
2
OUTPUT
20
Giải bài:
Một số được gọi là số tăng giảm nếu số đó có các chữ số thỏa mãn hoặc tăng dần, hoặc giảm dần từ trái qua phải.
Hãy đếm các số nguyên tố là số tăng giảm với số chữ số cho trước
INPUT
2
OUTPUT
20
Giải bài:
#include<iostream> #include<cmath> using namespace std; int n; bool nto(int x) { if(x < 2) return false; for(int i = 2; i <= sqrt(x); i++) if(x%i==0) return false; return true; } //1234 -> 4, 123, 3 < 4 bool tang(int x) { int t = x % 10; x/=10; while(x > 0) { if(t <= x%10) return false; t = x % 10; x/=10; } return true; } bool giam(int x) { int t = x % 10; x/=10; while(x > 0) { if(t >= x%10) return false; t = x % 10; x/=10; } return true; } void tanggiam() { cin >> n; int dem = 0; for(int i = pow(10, n-1); i < pow(10, n); i++) { if(nto(i) && ( tang(i) || giam(i))) { dem++; } } cout << dem; } int main() { tanggiam(); }
/******************************************************************************
Trả lờiXóaOnline C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include
#define ll long long
#define MAX 1000000
using namespace std;
bool de_or_in(int n)
{
bool in=true;
bool de=true;
while(n>=10)
{
int r=n%10;
n/=10;
if(rn%10) de=false;
if(in==de) return false;
}
return in || de;
}
void Condition_Prime_Sieve(bool a[],int n,int min,int maxs)
{
for(int i=0;i> n;
n--;
int min=1;
int max=1;
while(n--)
min*=10;
max=min*10;
n=max-min;
bool a[n];
Condition_Prime_Sieve(a,n,min,max);
}
int main()
{
cout<<"Hello World\n";
de_in_num();
return 0;
}