SRM 599 D2L2:BigFatInteger2, math
2014-02-17 00:03
246 查看
题目:http://community.topcoder.com/stat?c=problem_statement&pm=12870
代码:
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)
/*************** Program Begin **********************/
class BigFatInteger2 {
public:
map < long long, long long > extractPrimeFactors(int x)
{
map <long long, long long> ap;
for (int p = 2; p * p <= x; p++) {
int ex = 0;
bool flag = false;
while (x % p == 0) {
flag = true;
++ex;
x /= p;
}
if (flag) {
ap[p] = ex;
}
}
if (x != 1) {
ap[x] = 1;
}
return ap;
}
string isDivisible(int A, int B, int C, int D) {
auto ap = extractPrimeFactors(A);
auto cp = extractPrimeFactors(C);
for (auto it = cp.begin(); it != cp.end(); it++) {
if (ap[ (*it).first ] * B < (*it).second * D) {
return "not divisible";
}
}
return "divisible";
}
};
/************** Program End ************************/
代码:
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
#define CHECKTIME() printf("%.2lf\n", (double)clock() / CLOCKS_PER_SEC)
/*************** Program Begin **********************/
class BigFatInteger2 {
public:
map < long long, long long > extractPrimeFactors(int x)
{
map <long long, long long> ap;
for (int p = 2; p * p <= x; p++) {
int ex = 0;
bool flag = false;
while (x % p == 0) {
flag = true;
++ex;
x /= p;
}
if (flag) {
ap[p] = ex;
}
}
if (x != 1) {
ap[x] = 1;
}
return ap;
}
string isDivisible(int A, int B, int C, int D) {
auto ap = extractPrimeFactors(A);
auto cp = extractPrimeFactors(C);
for (auto it = cp.begin(); it != cp.end(); it++) {
if (ap[ (*it).first ] * B < (*it).second * D) {
return "not divisible";
}
}
return "divisible";
}
};
/************** Program End ************************/
相关文章推荐
- SRM 599 D1L1:BigFatInteger,math
- [找规律] SRM599 Hard FindPolygons
- SRM 599 DIV1
- [树形DP][状压DP] SRM599 950-point SimilarNames
- SRM 621 D2L3: MixingColors, math
- SRM 436 DigitsSwap (math)
- SRM 599 div2 250 500
- SRM 586 Div II Level Three: StringWeightDiv2,Dynamic Programming or Math
- SRM 621 D2L3: MixingColors, math
- SRM 628 D1L3:DoraemonPuzzleGame,math,期望,dp
- SRM 599 DIV 2
- SRM 617 D2L3: MyVeryLongCake, Math
- SRM 622 D2L3: Subsets, math, backtrack
- SRM 599 DIV2 950
- SRM 596 D2 L3:SparseFactorialDiv2,math
- SRM 622 D2L3: Subsets, math, backtrack
- SRM 599 D2L3: SimilarNames2,dp
- SRM 572 D2L3:DistinctRemainders,dp,math
- SRM 599 1A 2013.12.6
- SRM 628 D1L3:DoraemonPuzzleGame,math,后市展望,dp