Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我狠笨,所以用笨方法……0MS过

Posted by wsj19911101 at 2010-12-02 00:04:47 on Problem 1338
#include<iostream>
int main()
{
	int a[1501];
	a[1]=1;
	int p2=1,p3=1,p5=1;
	for(int i=2;i<=1500;i++)
	{
		int *x;
		int min=1000000000;
		int c2=a[p2]*2,c3=a[p3]*3,c5=a[p5]*5;
		if(min>c2){min=c2;x=&p2;}
		if(min>c3){min=c3;x=&p3;}
		if(min>c5){min=c5;x=&p5;}
		a[i]=min;
		(*x)++;
		while(a[p2]*2<=a[i])p2++;
		while(a[p3]*3<=a[i])p3++;
		while(a[p5]*5<=a[i])p5++;
	}
	int n;
	while(scanf("%d",&n)&&n)printf("%d\n",a[n]);
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator