topcode SRM 577 DIV2 EllysCoprimesDiv2
2013-04-28 21:31
295 查看
#include <iostream> #include <vector> #include <algorithm> using namespace std; class EllysCoprimesDiv2{ public: int gcd(int x,int y){ while(x){ int r = x; x = y%x; y=r; } return y; } int getCount(vector<int> numbers){ sort(numbers.begin(),numbers.end()); int cnt = 0; for(int i = 1; i < numbers.size(); i ++ ){ if(gcd(numbers[i-1],numbers[i]) != 1){ int j; for(j = numbers[i-1]+1; j < numbers[i]; j ++ ){ if(gcd(numbers[i-1],j) == 1 && gcd(j,numbers[i]) == 1){ cnt += 1; break; } } if( j >= numbers[i]) cnt +=2; } } return cnt; } };
相关文章推荐
- topcode SRM 577 DIV2 EllysNewNickname
- topcode SRM 577 DIV1 EllysRoomAssignmentsDiv1
- TopCoder SRM 140 Div2 第3题
- TopCoder SRM 668 Div2 Problem 1000 - AnArray (数学)
- TopCoder SRM 681 Div. 2 Problem 500 - ExplodingRobots (枚举)
- Topcoder SRM 688 div2
- Topcoder SRM 627 div1 HappyLettersDiv1 : 字符串
- Topcoder SRM 656 DIV2 1000 题解(动态规划)
- topcoder srm 518 div 2
- Topcoder SRM 652 DIV1 250
- topcoder SRM495 div1 level3
- TopCoder Practice SRMs -- SRM 144 DIV 1 -- 300p
- topcoder srm 519 div 1
- topcode srm SRM 557
- topcpder SRM 664 div2 A,B,C BearCheats , BearPlays equalPiles , BearSorts (映射)
- SRM 577 250 DIV2
- SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
- SRM DIV2 577 EllysRoomAssignmentsDiv2
- SRM 577 Div II Level Two: EllysRoomAssignmentsDiv2
- TopCode SRM 546: StrllRec_字符字典序剪枝