原创 HDU2.1.4 又見GCD

 放碼子: #include<iostream> #include<cstring> #include<string> #include<cstdio> #include<algorithm> using namespace std;

原创 Largest prime factor

 跟素數篩有相似處 另外:不要用while(cin>>n),會導致TLE(orz) #include<iostream> #include<cmath> #define maxn 1000005 using namespace std;

原创 整數對(hdoj 1271)

 題解: 這是一類題,叫做移除掉A的某一位後,再******* 其實也就是個數學題: 設刪掉的位是第k+1位,(k從0到len-1,最右邊爲第一位) 那麼有A=a*pow(10,k+1)+b*pow(10,k)+c B=a*pow(10,

原创 HDU2.1.5 找新朋友

 花裏胡哨的一堆東西,其實就是在區間[1,N],求N的互質數有多少個。 這裏引入一個歐拉函數的概念:(歐拉真的高產似母豬) f(n)=n*Π((p-1)/p) p爲n的質因數 #include<iostream> #include<cs

原创 The Seven Percent Solution

#include <iostream> #include "stdio.h" #include "string.h" using namespace std; int main() { char c[1000]; wh

原创 HDU1.2.6Just A Triangle

#include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define maxn 1050 using name

原创 HDU1.3.1FatMouse' Trade

  #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define maxn 1050 using na

原创 HDU who's in the middle

直接快排 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #define maxn 10050 usin

原创 HDU2.1.1 最小公倍數

  最小公倍數就是(a*b/最大公因數) 最大公因數採用輾轉相除法。 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algo

原创 HDU 2138 How many prime numbers

 記得 sqrt(a*1.0)或者 sqrt(a)+1 不然開根開出來後會取整,導致wrong answer #include<iostream> #include<cstring> #include<cstdio> #include<

原创 HDU1.3.2 百步穿楊

注意一個問題:他要求按箭的小大順序排序輸出。 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #defi

原创 HDU1.3.5排序

這題有點意思, 注意幾點:1.在判斷s[i]!='5'時,記得加上一個判斷i<s.length(),因爲有可能最後一個數不是'5',那麼它會繼續訪問s[s.length()-1]的後一個,也就是會越界,爆出Runtime Error 2.

原创 兩種快速篩選素數的方法:埃式和歐拉篩法

 兩種篩選素數的方法:埃式和歐拉篩法 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> #include<algorithm> #include<

原创 HDU Identity Card

 注意輸出格式,是一句話,一定要帶"." 再之後就是按月/日/年輸出 題目看清楚33後面的4個0可以被其他的數字代替。 #include<iostream> #include<cstring> #include<cstdio> #def

原创 warshell算法

warshell算法是用來求關係R的傳遞閉包t(R)的。 傳統的t(R)算法:R+R^2+R^3+....... 當R^n出現循環時,R+R^2+......R^n即爲t(R) warshell算法:假設存在C作爲中間路徑,取C=0,遍歷