#13701: 拜託幫我將錯誤糾正


jackyname1@gmail.com (☆♬○♩程式家小崴●♪✧♩)


過不了~~~

第四組測資 算不出來

拜託幫我將錯誤糾正 <<< thanks !!!!!!


#include <stdio.h>
#include <iostream>
using namespace std;

int dig[] = {1, 1, 2, 6, 4, 2, 2, 4, 2, 8};

int lastNon0Digit(int n)
{
if (n < 10)
return dig[n];

// Check whether tens (or second last) digit
// is odd or even
// If n = 375, So n/10 = 37 and (n/10)%10 = 7
// Applying formula for even and odd cases.
if (((n/10)%10)%2 == 0)
return (6*lastNon0Digit(n/5)*dig[n%10]) % 10;
else
return (4*lastNon0Digit(n/5)*dig[n%10]) % 10;
}

int main()
{
int n,m;
while(cin>>n){
while(n--){
cin>>m;
cout<<lastNon0Digit(m)<<endl;
}
}

return 0;
}

#13703: Re:拜託幫我將錯誤糾正


justinO__o (夜貓)


過不了~~~

第四組測資 算不出來

拜託幫我將錯誤糾正 <<< thanks !!!!!!


#include
#include
using namespace std;

int dig[] = {1, 1, 2, 6, 4, 2, 2, 4, 2, 8};

int lastNon0Digit(int n)
{
if (n < 10)
return dig[n];

// Check whether tens (or second last) digit
// is odd or even
// If n = 375, So n/10 = 37 and (n/10)%10 = 7
// Applying formula for even and odd cases.
if (((n/10)%10)%2 == 0)
return (6*lastNon0Digit(n/5)*dig[n%10]) % 10;
else
return (4*lastNon0Digit(n/5)*dig[n%10]) % 10;
}

int main()
{
int n,m;
while(cin>>n){
while(n--){
cin>>m;
cout<<lastNon0Digit(m)<<endl;
}
}

return 0;
}




好像要long long

#16278: Re:拜託幫我將錯誤糾正


rollfc (點石學園 StoneCampus)


不好意思 想藉文章串討論問一下這個規律是怎麼推導出來的

因為這題和 c055: 00568 - Just the Facts 題目敘述是一樣但問題是測資範圍大了許多

網路上找到的答案有兩種 一種是做質因數分解,先把2和5的因數濾出來相互消去,最後再乘回去

另一種是只說保留最後六位數即可(但原因皆不解釋或只會直呼好神奇....)

顯然上述兩種方法皆無法處理這個問題,所以想問一下這個規律是怎麼推導出來的

先謝謝高手們的回覆