Question one hundred and twenty: the lucky spot

Source: Internet
Author: User

[Plain] Description
 
It was clearly because he was born in March 3, 1993. The year of his birth, the number of months and the date all had numbers 3. He thought that the number containing numbers 3 was his lucky number, he even liked the number of multiples of 3 and thought it was his lucky number. Now he gives a positive integer N. Please help us calculate the number between 1 and N (including 1 and N) there are several numbers that are clearly known as lucky ones.
 
Input
 
The input data has only one positive integer N (N <= 32767 ).
 
Output
 
The output data has only one integer, which is the number of lucky numbers between 1 and N.
 
Sample Input
 
 
10
 
Sample Output
 
 
3

Description

It was clearly because he was born in March 3, 1993. The year of his birth, the number of months and the date all had numbers 3. He thought that the number containing numbers 3 was his lucky number, he even liked the number of multiples of 3 and thought it was his lucky number. Now he gives a positive integer N. Please help us calculate the number between 1 and N (including 1 and N) there are several numbers that are clearly known as lucky ones.

Input

The input data has only one positive integer N (N <= 32767 ).

Output

The output data has only one integer, which is the number of lucky numbers between 1 and N.

Sample Input


10

Sample Output


3
 


[Plain] # include <stdio. h>
 
Int check (int num );
 
Int main ()
{
Int I;
Int count;
Int num;

Count = 0;
Scanf ("% d", & num );
 
For (I = 1; I <= num; I ++)
{
If (I % 3 = 0)
{
Count ++;
}
Else if (check (I ))
{
Count ++;
}
}
 
Printf ("% d", count );
}
 
Int check (int num)
{
Int flag = 0;
 
While (num)
{
If (num % 10 = 3)
{
Flag = 1;
}
Num/= 10;
}
 
Return flag;
}

# Include <stdio. h>

Int check (int num );

Int main ()
{
Int I;
Int count;
Int num;

Count = 0;
Scanf ("% d", & num );

For (I = 1; I <= num; I ++)
{
If (I % 3 = 0)
{
Count ++;
}
Else if (check (I ))
{
Count ++;
}
}

Printf ("% d", count );
}

Int check (int num)
{
Int flag = 0;

While (num)
{
If (num % 10 = 3)
{
Flag = 1;
}
Num/= 10;
}

Return flag;
}

 


 

Related Article

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.