for the sum of the =n+n of the given function d (n), n is a positive integer, such as D (78) =78+7+8=93. This function can be seen as a generator, as 93 can be seen as generated by 78.
Define number A: number A cannot find a number B can be =a by D (b), that is, a cannot be generated by another number. Now write the program to find out all the number a definitions in 1 to 10000.
Reply:
Request a bool array of length 10000, each representing whether the corresponding value can have other numbers generated. Initializes the values in the array to false at the beginning.
Since the number of numbers greater than 10000 must be greater than 10000, we simply traverse the numbers from 1 to 10000, calculate the number of builds, and set the corresponding value in the bool array to true, indicating that the number can have other numbers generated.
The integer corresponding to the position in the last bool array where the value is false is not generated by any other number.
Here is the code I wrote.
#include <iostream>
using namespace Std;
void SCS (int n)
{
int i;
BOOL *a=new bool[n+1];
memset (a,false,n+1);
int m=0,s=0,p=0,q=0;
for (i=1;i<=n;i++)
{
m=i%10;
p= (I/10)%10;
Q= (i/100)%10;
S= (i/1000)%10;
if (i+m+p+q+s<=n)
{
A[i+m+p+q+s]=true;
}
}
for (i=0;i<=n;i++)
{
if (A[i])
cout<<i<<endl;
}
}
int main ()
{
int n;
cout<< "Please cin the max Num:" <<endl;
cin>>n;
SCS (n);
return 0;
}
Baidu Noodle question find an array that satisfies the conditions