pku2591.java

来自「这是ACM 方面的资料 是PKU的 北京大学的出来的」· Java 代码 · 共 40 行

JAVA
40
字号
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[]) throws Exception
	{
		Scanner cin=new Scanner(System.in);
		int two,three,i,t1,t2,n;
		int s[]=new int[10000000];
		two=three=0;
		s[0]=1;
		for(i=1;i<10000000;i++)
		{
			t1=2*s[two]+1;
			t2=3*s[three]+1;
			if(t1<t2)
			{
				s[i]=t1;
				two++;
			}
			else if(t1>t2)
			{
				s[i]=t2;
				three++;
			}
			else
			{
				s[i]=t1;
				three++;
				two++;
			}
		}
		while(cin.hasNext())
		{
			n=cin.nextInt();
			System.out.println(s[n-1]);
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?