#25819: to:用迴圈寫的人


morrisddd (MORRIS 范智傑)

學校 : 國立臺灣科技大學
編號 : 126549
來源 : [23.93.64.134]
最後登入時間 :
2023-11-23 12:57:22
d485. 我愛偶數 -- 板橋高中教學題 | From: [111.243.32.225] | 發表日期 : 2021-06-24 18:13

絕對超時,請用sum = (a-b)/2,在判斷四種能

 

 
#26203: Re:to:用迴圈寫的人


dfd8282@gmail.com (fishhh)

學校 : 嘉義市私立嘉華高級中學
編號 : 99760
來源 : [163.27.13.253]
最後登入時間 :
2024-04-12 13:39:58
d485. 我愛偶數 -- 板橋高中教學題 | From: [1.173.141.156] | 發表日期 : 2021-07-22 23:26

絕對超時,請用sum = (a-b)/2,在判斷四種能

 

我實測過了

其實並不會TLE

當然用公式解會快很多~

AC (0.7s, 340KB)

 

附上程式碼::

#include<iostream> using namespace std; int main(){ long long a,b,tot=0; cin>>a>>b; for(int i=a;i<=b;i++){ tot+=(i%2==0); } cout<<tot; }

 
#26204: Re:to:用迴圈寫的人


arief6499@gmail.com (Muhammad Arief)

學校 : 不指定學校
編號 : 159267
來源 : []
最後登入時間 :
2021-07-22 23:51:03
d485. 我愛偶數 -- 板橋高中教學題 | From: [103.142.224.11] | 發表日期 : 2021-07-22 23:51

絕對超時,請用sum = (a-b)/2,在判斷四種能

 

我實測過了

其實並不會TLE

當然用公式解會快很多~

AC (0.7s, 340KB)

 

附上程式碼::

#include using namespace std; int main(){ long long a,b,tot=0; cin>>a>>b; for(int i=a;i<=b;i++){ tot+=(i%2==0); } cout<<tot; }


good article, if you need information related to similar articles you can access it here - http://news.unair.ac.id/en/2021/03/15/covid-vaccines-able-to-neutralize-new-variant-virus/

 
#27060: Re:to:用迴圈寫的人


s010400@student.cysh.cy.edu.tw (許家維)

學校 : 國立嘉義高級中學
編號 : 163342
來源 : [1.173.208.2]
最後登入時間 :
2023-12-19 23:43:29
d485. 我愛偶數 -- 板橋高中教學題 | From: [163.27.3.91] | 發表日期 : 2021-09-11 15:30

絕對超時,請用sum = (a-b)/2,在判斷四種能

 

我實測過了

其實並不會TLE

當然用公式解會快很多~

AC (0.7s, 340KB)

 

附上程式碼::

#include using namespace std; int main(){ long long a,b,tot=0; cin>>a>>b; for(int i=a;i<=b;i++){ tot+=(i%2==0); } cout<<tot; }

絕對超時,請用sum

 
ZeroJudge Forum