Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- const int LIMIT = int(2e5)+1;
- public:
- int countDifferentSubsequenceGCDs(vector<int>& nums) {
- int count=0;
- vector<bool> m(LIMIT, false);
- for(int x: nums)
- m[x] = true;
- for(int i=1; i<=LIMIT; i++){
- int g = 0;
- for(int j=i; j<=LIMIT && g != i; j+=i)
- if(m[j]) g = __gcd(g, j);
- if(g == i) count++;
- }
- return count;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement