1248 Problem -AO- beautiful number - Getting title - mathematics -C ++ realization

Problem AO: beautiful number

Time limit: 1 Sec memory limit: 32 MB
submitted: 191 solution: 47

Title Description

Xiao Ming is very fond of these two numbers 3 and 5, he will be number 3 or 5 divisible number is called beautiful. You are given an integer N (1 <= N <= 100000), you can tell Bob N-th beautiful number is?

Entry

Test input comprising a plurality of sets of data. Each input an integer N (1 <= N <= 100000).

Export

For each input and output of the N number of beauty.

Sample input  Copy

1
2
3
4

Sample output  Copy

3
5
6
9

Code

prompt:

  • Do its array
  • And then outputs the corresponding
  • While not the input side of computing, prone to time-out
#include<stdio.h>
int a[100010];//建立一个数组a[ ]来存所有的美丽数 
int main()
{
	int n,i;
	int t=0;//用来记录个数 
	for(i=3;;i++)
	{
		if(i%3==0||i%5==0)
		a[++t]=i;
		if(t>100010)
		  break;
	}
	while(scanf("%d",&n)!=EOF)
	{
		printf("%d\n",a[n]);
	}
	return 0;
}

 

Published 20 original articles · won praise 0 · Views 35

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/104737001