#34094: C遞迴解法(好像效率會比較好)


zxc123asd66@gmail.com (毛喬)

School : No School
ID : 225894
IP address : [27.242.229.116]
Last Login :
2023-05-15 16:19:52
c039. 00100 - The 3n + 1 problem -- UVa100 | From: [125.231.100.231] | Post Date : 2023-02-28 04:38

設一個函式

 

看他是偶數

return 1/2該值

 

看他是奇數

return 3 * a + 1該值

 

參考解

 

 
#35856: Re: C遞迴解法(好像效率會比較好)


900131shawn@gmail.com (nocmos_0623)

School : No School
ID : 124194
IP address : [140.112.230.169]
Last Login :
2024-06-22 21:19:17
c039. 00100 - The 3n + 1 problem -- UVa100 | From: [115.165.216.180] | Post Date : 2023-06-19 17:39

設一個函式

 

看他是偶數

return 1/2該值

 

看他是奇數

return 3 * a + 1該值

 

參考解

 

遞迴效率跟編譯器最佳化有關

 
ZeroJudge Forum