#10351: TLE (逾時)

#### davidrfdg (unknown)

School : No School
ID : 53162
IP address : [125.227.255.80]
Last Login ：
2015-10-27 13:26:31
d639. 企鵝村三兄弟penguin -- | From: [220.137.19.184] | Post Date : 2015-10-13 21:30

import java.util.Scanner;

public class D639 {

public static void main(String[] args) {

double a = 1., b = 1., c = 1., sum = 0.;

Scanner input = new Scanner(System.in);

while (input.hasNextInt()) {

int n = input.nextInt();

if (n <= 3) {

System.out.println(1);

} else {

for (int i = 4; i <= n; i++) {

sum = a + b + c;

a = b;

b = c;

c = sum;

sum%=10007;    //本來沒這行，這行是後來才加的，還是過不了

}

System.out.print((int)sum);

}

sum = 0;

a = 1;

b = 1;

c = 1;

}

input.close();

}

}

#10828: Re:TLE (逾時)

#### p3a_owhj (阿普二信)

School : No School
ID : 39897
IP address : [36.227.79.178]
Last Login ：
2024-06-04 22:09:36
d639. 企鵝村三兄弟penguin -- | From: [203.77.43.132] | Post Date : 2016-04-01 22:41

n的值超過10^9不可能迴圈跑10億次不逾時的

2列1欄的向量<f(n+2),f(n+1)> = 2x2陣列Ａ 乘上  2x1的向量<f(n+1),f(n)> = .... = An 乘上  2列1欄的向量<f(2),f(1)>即< 1 , 1 >

1 0

int binpow(int x , int n , int mod)

{

p=1;

for(i=0; i<k; ++k)
{
p = p*p%mod;
if(b[i]) p*x%mod;
}

return p;

}

#10829: Re:TLE (逾時)

#### p3a_owhj (阿普二信)

School : No School
ID : 39897
IP address : [36.227.79.178]
Last Login ：
2024-06-04 22:09:36
d639. 企鵝村三兄弟penguin -- | From: [203.77.43.132] | Post Date : 2016-04-01 22:47

http://zerojudge.tw/ShowThread?postid=10758&reply=0

ZeroJudge Forum