Baidu Noodle question find an array that satisfies the conditions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.