id
int64
1
3.58k
problem_description
stringlengths
516
21.8k
instruction
int64
0
3
solution_c
dict
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n\n long long fun(vector<int>&tar, int st, int en){\n vector<int>v;\n for(int i=st; i<en;i++) v.push_back(abs(tar[i]));\n int n=v.size();\n vector<int> pre(n), su(n), use_me;\n \n\n for(int i=0;i<v.size();i++){\n while(use_me...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n vector<long long> D;\n for(int i=0;i<n;i++){\n D.push_back(target[i]-nums[i]);\n }\n long long op = 0;\n vector<vector<long long...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n\n long long solve(long long n,int k, vector<int>& nums, vector<vector<long long>>& dp)\n {\n if(n == -1) return 0;\n if(dp[n][k] != -1) return dp[n][k];\n if(k == 2)\n {\n if(nums[n] >= 0)\n {\n return nums[n...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "#include <vector>\n#include <cmath>\n#include <iostream>\nusing namespace std;\n\nlong long solve(const vector<int>& li) {\n int pre = li[0];\n int a = -1, b = -1;\n long long cost = 0;\n for (const auto& el : li) {\n if (el >= pre) {\n if (a == -1) {\n a = pre;...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long cnt=0;\n void fun(vector<int>v){\n int n=v.size();\n cnt+=v[0];\n for(int i=1;i<n;i++){\n if(v[i]>v[i-1]){\n cnt+=v[i]-v[i-1];\n }\n }\n }\n long long minimumOperations(vector<int>& nums, vect...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long ans = 0;\n static bool compare(pair<int,int>&a, pair<int,int>&b){\n if(a.first<b.first)return true;\n else if(a.first>b.first)return false;\n else return a.second<b.second;\n }\n \n void cal(int l, int r, vector<int>& nums, vector<i...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\n private:\n vector<vector<int>> helper(vector<int>& diff){\n int n = diff.size();\n\n vector<vector<int>> groupings;\n int currIndex = -1;\n int currState = 0;\n\n for(int i = 0; i < n; i++){\n // cout << i << \": \" << diff[i] << \" \";...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "#define ll long long\n#define vll vector<ll>\n#define vvll vector<vll>\n#define pb push_back\nclass Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n ll n=nums.size();\n for(ll i=0; i<n; i++){\n target[i]-=nums[i];\n }\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n long incr = 0, decr = 0, ops = 0;\n\n for (int i = 0; i < n; i++) {\n long diff = target[i] - nums[i];\n\n if (diff > 0) {\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int prev = 0;\n long long operations = 0;\n\n for (int i = 0; i < nums.size(); i++) {\n int curr=target[i]-nums[i];\n if (curr < 0) {\n prev = min...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n long incr = 0, decr = 0, ops = 0;\n\n for (int i = 0; i < n; i++) {\n long diff = target[i] - nums[i];\n\n if (diff > 0) {\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n long increase = 0, decrease = 0, operations = 0;\n\n for (int i = 0; i < n; ++i) {\n int difference = target[i] - nums[i];\n\n if (difference > 0) {\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n for(int i=0;i<nums.size();i++){\n nums[i]=target[i]-nums[i];\n }\n long long carry=0,ans=0;\n for(int i=0;i<nums.size();i++){\n // cout<<carry<<\" \"<<ans...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n long long ans=0;\n long long int n=nums.size();\n int tinc=0,tdec=0;\n for(int i=0;i<n;i++){\n if(nums[i]<target[i]){\n long long t=0;\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <algorithm>\n\nusing namespace std;\n\n#define ll long long\n\nclass SGT \n{\npublic:\n vector<pair<ll, int>> seg;\n\n SGT(int n) \n {\n seg.resize(4 * n + 1, {1e17, -1}); // Initialize with a large value and invalid index\n }\n\n void...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0; }();\n\nclass Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n long long res = 0;\n for (int i = 0, N = size(nums), prv = 0; i < N; ++i) {\n int cur = target[i] - nums[i]...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(std::vector<int>& nums, std::vector<int>& target) {\n std::vector<int> stack;\n long long ans = 0;\n\n auto add = [&ans, &stack](int value) {\n if (stack.size() < 2)\n stack.push_back(value);\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "static const int speedup = []{ios::sync_with_stdio(0); cin.tie(0); return 0;}();\n\nclass Solution {\npublic:\n long long minimumOperations(std::vector<int>& nums, std::vector<int>& target) {\n std::pair<int, int> stack = {};\n long long ans = 0;\n auto add = [&ans, &stack](int valu...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n long long ans = 0,incOp = 0, decOp = 0;\n vector<int>diff(n,0);\n for(int i = 0; i<n; i++){\n diff[i] = nums[i]-target[i];\n }\n\n ...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n long long ans = 0;\n vector<int> diff(nums.size());\n // diff[0] = nums[i];\n for(int i=0;i<nums.size();i++) {\n diff[i] = target[i] - nums[i];\n }\n a...
3,454
<p>You are given two positive integer arrays <code>nums</code> and <code>target</code>, of the same length.</p> <p>In a single operation, you can select any subarray of <code>nums</code> and increment each element within that subarray by 1 or decrement each element within that subarray by 1.</p> <p>Return the <strong...
3
{ "code": "class Solution {\npublic:\n long long minimumOperations(vector<int>& nums, vector<int>& target) {\n int n = nums.size();\n vector<int> a(n);\n for(int i=0; i<n; ++i) a[i] = target[i] - nums[i];\n for(int i=n-1; i>0; --i) a[i] -= a[i-1];\n long long s = 0, t = 0;\n ...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int singledigitsum=0;\n int doubledigitsum=0;\n for(int i=0; i<nums.size();i++){\n if(nums[i]<10){\n singledigitsum += nums[i];\n\n }\n else{\n doubledi...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int asw=0,bsw=0,adw=0,bdw=0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<10) asw=asw+nums[i];\n else bsw=bsw+nums[i];\n }\n for(int i=0;i<nums.size();i++){\n if(nums[i]>10)...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int sum=0;\n int sum1=0;\n for(auto x:nums)\n {\n sum+=x;\n if(x/10==0)\n {\n sum1+=x;\n }\n }\n int sum2=sum-sum1;\n if(sum2==s...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int sum1 = 0, sum2 = 0;\n for (auto val:nums)\n {\n if (val < 10) sum1 += val;\n else sum2 += val;\n }\n return sum1 != sum2;\n }\n};", "memory": "28000" }
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int n = nums.size();\n int singleSum = 0;\n int DoubleSum = 0;\n int cou = 0;\n for (int i = 0; i < n; i++) {\n if (nums[i] <= 9) {\n singleSum += nums[i];\n }\n ...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int sum1 = 0, sum2 = 0;\n for(int i=0;i<nums.size();i++){\n if(nums[i]<10){\n sum1+=nums[i];\n }\n else{\n sum2+=nums[i];\n }\n }\n re...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
0
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int single = 0;\n int double1 =0;\n for(int i=0; i<nums.size(); i++)\n {\n if(nums[i]< 10 && nums[i]> 0)\n {\n single +=nums[i];\n }\n else if(nums[i...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
2
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int sumSingleDigit = 0;\n int sumDoubleDigit = 0;\n for (int num : nums) {\n if (num >= 1 && num <= 9) {\n sumSingleDigit += num;\n } else if (num >= 10 && num <= 99) {\n ...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
2
{ "code": "class Solution {\npublic:\n bool canAliceWin(vector<int>& nums) {\n int n = nums.size();\n int s=0,d=0;\n for(int i=0;i<n;i++){\n if(nums[i]<10){\n s+=nums[i];\n }\n else{\n d+=nums[i];\n }\n }\n ...
3,515
<p>You are given an array of <strong>positive</strong> integers <code>nums</code>.</p> <p>Alice and Bob are playing a game. In the game, Alice can choose <strong>either</strong> all single-digit numbers or all double-digit numbers from <code>nums</code>, and the rest of the numbers are given to Bob. Alice wins if the ...
3
{ "code": "class Solution {\nprivate:\n bool CheckTwoDigit(int num)\n {\n num=num/10;\n return num;\n } \npublic:\n bool canAliceWin(vector<int>& nums) {\n int TwoDigitSum=0;\n int OneDigitSum=0;\n for(int i=0;i<nums.size();i++)\n {\n if(CheckTwoDigit(...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
0
{ "code": "int init = [] {\n cin.tie(nullptr)->sync_with_stdio(false);\n freopen(\"user.out\", \"w\", stdout);\n\n vector<bool> isPrime(31622, true);\n for (int i = 2; i <= 31622; ++i) {\n if (isPrime[i]) {\n for (int j = i * i; j <= 31622; j += i)\n isPrime[j] = false;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
0
{ "code": "class Solution {\npublic:\n\n bool isPrime(int num) {\n // std::cout<<num<<std::endl;\n int root = sqrt(num);\n // std::cout<<\" Root is\"<<root<<std::endl;\n for(int i=2;i<=root;i++) {\n if(num%i==0) {\n return false;\n }\n }\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "class Solution {\npublic:\nbool isPrime(int n)\n{\n if (n <= 1)\n return false;\n for (int i = 2; i <= n / 2; i++)\n if (n % i == 0)\n return false;\n\n return true;\n}\n\n int nonSpecialCount(int l, int r) {\n vector<int> vect;\n \n for(int i=floor...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "#include <bits/stdc++.h>\n\n#define FOR(i, l, r) for (int i = l; i < r; ++i)\n#define FORR(i, r, l) for (int i = r; i >= l; --i)\n#define FORI(n) FOR(i, 0, n)\n#define FORJ(n) FOR(j, 0, n)\n#define FORK(n) FOR(k, 0, n)\n#define loop(n) FOR(_, 0, n)\n#define all(x) x.begin(), x.end()\n#define sz(x) x.size()...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "\nusing Factor = pair<int, int>;\n\nconstexpr int MAX_SIEVE = 1e6 + 5;\nstruct PrimeTable {\n vector<int> minp, primes;\n\n PrimeTable(int n) {\n sieve(n);\n }\n\n void sieve(int n) {\n minp.assign(n + 1, 0);\n primes.clear();\n \n for (int i = 2; i <= n; i++)...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "class Solution {\npublic:\n int c(int k){\n cout << k << '\\n'; \n vector<bool> p(k+1, true);\n if(k == 1){\n return 0; \n }\n p[1] = false; \n p[2] = true;\n for(int i = 2; i <= k; i++){\n if(p[i]){\n for(int j = i * ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "class Solution {\npublic:\n vector<int> SieveOfEratosthenes(int n)\n {\n bool prime[n + 1];\n memset(prime, true, sizeof(prime));\n \n for (int p = 2; p * p <= n; p++) {\n \n if (prime[p] == true) {\n for (int i = p * p; i <= n; i += p)\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "const long long MAX = 1e6;\nvector<long long> arr(MAX + 1, 1);\n\n\nvoid sieve() {\n \n arr[0] = 0;\n arr[1] = 0;\n \n for (long long i = 2; i * i <= MAX; i++) {\n if (arr[i] == 1) { \n for (long long j = i * i; j <= MAX; j += i) {\n arr[j] = 0; \n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "class Solution {\npublic:\n bool isPrime(int n) {\n if (n <= 1) return false;\n if (n <= 3) return true;\n if (n % 2 == 0 || n % 3 == 0) return false;\n for (int i = 5; i * i <= n; i += 6) {\n if (n % i == 0 || n % (i + 2) == 0)\n return false;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
2
{ "code": "class Solution {\n\npublic:\n int nonSpecialCount(int l, int r) {\n vector<long long> primes;\n for(long long i=2;i*i<=r;i++)\n {\n bool f=0;\n for(int j=2;j*j<=i;j++)\n {\n if(i%j==0)f=1;\n }\n if(!f)primes.push_...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> findPrime(int limit) {\n vector<bool> isPrime(limit + 1, true);\n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i * i <= limit; ++i) {\n if (isPrime[i]) {\n for (int j = i * i; j <= limit; j += i) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> findPrime(int limit) {\n vector<bool> isPrime(limit + 1, true);\n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i * i <= limit; ++i) {\n if (isPrime[i]) {\n for (int j = i * i; j <= limit; j += i) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n\n vector<int> p;\n vector<long long int> p_s;\n\n\n\n void prime(int r) {\n\n if (p_s.size() != 0) \n return;\n\n p.push_back(2);\n\n bool f = false;\n for (int i = 3; i <= sqrt(r + 10); i+=2) {\n f = false;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n\n vector<int> p;\n vector<long long int> p_s;\n\n\n\n void prime(int r) {\n\n if (p_s.size() != 0) \n return;\n\n p.push_back(2);\n\n bool f = false;\n for (int i = 3; i <= sqrt(r + 10); i+=2) {\n f = false;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> sieve(int n) {\n vector<bool> check(n + 1, true);\n vector<int> ans;\n check[0] = false;\n check[1]=false;\n\n for (int p = 2; p * p <= n; ++p) {\n if (check[p]) {\n for (int i = p * p; i <= n; i += p) {\n check[i] = f...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int helper(int peak,vector<bool> v){\n int ans=0;\n for(long long i=2;i*i<=peak;i++){\n if(v[i]==true && i*i<=peak) ans++;\n }\n return peak-ans;\n }\n\n int nonSpecialCount(int l, int r) {\n vector<bool> v(50000,true); \n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n typedef long long ll;\n vector<ll>sieve(ll n){\n vector<bool>p(n+1, true);\n p[0]=p[1]=false;\n for(ll i = 2; i*i<=n;i++) {\n if (p[i]) {\n for (ll j=i*i;j<=n; j+=i) {\n p[j] = false;\n }\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<long long> sieve(long long max) {\n vector<bool> is_prime(max + 1, true);\n is_prime[0] = is_prime[1] = false;\n for (int i = 2; i * i <= max; ++i) {\n if (is_prime[i]) {\n for (int j = i * i; j <= max; j += i) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n int n=sqrt(r);\n vector<int>sieve(n+1,1);\n vector<int>prime;\n sieve[0]=sieve[1]=0;\n for(int i=2;i<=n;i++)\n {\n if(sieve[i])\n {\n prime.push_back(i);\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n int n = sqrt(r);\n vector<int> isPrime(n + 1, true);\n vector<int> prime;\n isPrime[0] = isPrime[1] = false;\n for (int p = 2; p <= n; p++){\n if (isPrime[p]){\n prime.push_back...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "\nclass Solution {\npublic:\n \n std::vector<int> primes;\n\n Solution() {\n soe(31622);\n }\n\n void soe(int n) {\n std::vector<bool> isprime(n + 1, true);\n for (int i = 2; i * i <= n; ++i) {\n if (isprime[i]) {\n for (int j = i * i; j <= n; j...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n int mx=sqrt(1e9);\n \n vector<bool> isPrime(mx+1,true);\n \n vector<int> p;\n for(int i=2;i*i<=mx;i++){\n if(isPrime[i]){\n \n for(int j=i*i;j<=mx;j+=i){\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n void sieveOfEratosthenes(int n,vector<int>&primeNUmber) {\n std::vector<bool> isPrime(n + 1, true);\n isPrime[0] = isPrime[1] = false; // 0 and 1 are not prime numbers\n\n for (int p = 2; p * p <= n; p++) {\n if (isPrime[p]) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n\n int nonSpecialCount(int l, int r) {\n int n=sqrt(r)+1;\n vector<int>Primes(n);\n vector<bool>V(n+1,true);\n \n V[0]=V[1]=false;\n \n for(int i=2;i<n;++i)\n {\n if(V[i])\n {\n Primes.pu...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> gs(int limit) {\n vector<bool> isp(limit + 1, true);\n isp[0] = isp[1] = false;\n for (int i = 2; i * i <= limit; ++i) {\n if (isp[i]) {\n for (int j = i * i; j <= limit; j += i) {\n isp[j] = false;\n }\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\n vector<int> sieve(int n) {\n vector<bool> is_prime(n + 1, true);\n is_prime[0] = is_prime[1] = false;\n for (int p = 2; p * p <= n; ++p) {\n if (is_prime[p]) {\n for (int i = p * p; i <= n; i += p) {\n is_prime[i] = false;\n }\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "#define ll long long\nclass Solution {\n vector<ll> primes(int n) {\n vector<ll> res;\n vector<ll>vis(sqrt(n)+2,0);\n res.push_back(1);\n for (ll i = 2; i * i <= n; i++) {\n for(ll j=i*i;j*j<=n;j+=i){\n vis[j]=1;\n }\n if(!vis[i]...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n \n int n = sqrtl(r);\n vector<long long> v,is_Prime(n+1,1);\n is_Prime[0] = 0;\n is_Prime[1] = 0;\n \n\n for (int i = 2; i*i <= n; i++) {\n if (is_Prime[i]==1) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n std::vector<int> primes = sieveOfEratosthenes((int) sqrt(1e9));\n std::unordered_set<int> specialNumbers;\n\n for (int prime : primes) {\n long long square = (long long) prime * prime;\n if (squa...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "bool flag = 0;\nvector<int> primes, isPrime;\n\nvoid calc(){\n if(flag)\n return;\n \n flag = 1;\n int maxLimit = 1e7;\n isPrime.resize(maxLimit+3,1);\n \n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i * i <= maxLimit; ++i) {\n if (isPrime[i]) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> Eratosthenes(int n)\n {\n vector<int>q(n+1,0);\n vector<int>primes;\n for (int i=2; i<=sqrt(n); i++)\n {\n if (q[i]==1) continue;\n int j=i*2;\n while (j<=n)\n {\n q[j]=1;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "\nclass Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n build();\n int total = r - l + 1;\n for (auto& prime : primes) {\n if (prime * prime >= l && prime * prime <= r) {\n total --;\n }\n }\n return total;\n }\n\npri...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n \n bool isPrime(int n)\n{\n // Corner case\n if (n <= 1)\n return false;\n\n // Check from 2 to square root of n\n for (int i = 2; i <= sqrt(n); i++)\n if (n % i == 0)\n return false;\n\n return true;\n}\n \n \n int nonSpeci...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int>v;\n bool isPrime(int N)\n{\n\n // If the number is less than or equal to 1,\n // it is not prime\n if (N <= 1) {\n return false;\n }\n\n // If the number is 2 or 3, it is prime\n if (N <= 3) {\n return true;\n }\n\n // If t...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n // square of a prime\n primeGen(r);\n return (r - l + 1) - (primes.end() - lower_bound(primes.begin(), primes.end(), l));\n }\n\n vector<int> primes;\n set<int> remaining;\n\n void primeGen(int r) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> primes;\n bool ran=0;\n void once() {\n if (ran) return;\n ran = 1;\n int mx = 4e4;\n vector<bool> prime(mx, 1);\n for (int i = 2; i < mx; i++) {\n if (prime[i]) {\n primes.push_back(i);\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "constexpr int N = 40000;\nclass Solution {\npublic:\n Solution() : isPrime(1 + N, true) {\n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i <= N; ++i) {\n if (isPrime[i]) {\n prime.emplace_back(i);\n }\n for (int j = i * i; j <= N; j += ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\nprivate:\n int solve(vector<int>& v, int k) {\n return upper_bound(v.begin(),v.end(),k)-v.begin();\n }\npublic:\n int nonSpecialCount(int l, int r) {\n vector<bool> primes(4e4,true);\n vector<int> sq;\n primes[1] = false;\n for(int i=2;i<4e4;i++...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> findPrimes(){\n int n=50000;\n vector<bool> v(n,true);\n for(int j=2;j*j<n;j++){\n if(v[j]){\n for(int k=j*j;k<n;k+=j){\n v[k]=false;\n }\n }\n }\n vector<int...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\n vector<int> g;\npublic:\n void gg() {\n bool isNT[100101] = {};\n int R = sqrt(1000000000);\n for (int i=2; i*i <= R; i++) {\n if (isNT[i]) continue;\n for (long long j = i*i; j <= R; j+= i)\n isNT[j] = true;\n }\n\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\nprivate:\n vector<bool> prime;\n vector<long long> primes;\npublic:\n Solution() {\n int n = 32000;\n prime.resize(n + 1, true);\n prime[0] = prime[1] = false;\n \n for (int p = 2; p * p <= n; p++) {\n if (prime[p] == true) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\n \n public:\n vector<bool> isPrime;\n vector<long long>t;\n\n Solution() {\n int maxn=32000;\n isPrime.assign(maxn + 1, true);\n isPrime[0] = isPrime[1] = false; \n \n for (int i = 2; i * i <= maxn; ++i) {\n if (isPrime[i]) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> prime;\n vector<int> vec;\n Solution(){\n int num = 31623;\n vector<bool> isPrime(num+1 , true);\n\n\n for(int i=2 ; i*i < num ; i++ ){\n if(isPrime[i]){\n for(int j=i*i ; j<num ; j+=i){\n isP...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> sieve(int ml) {\n vector<bool> is_prime(ml + 1, true);\n vector<int> primes;\n is_prime[0] = is_prime[1] = false;\n for (int i = 2; i <= ml; ++i) {\n if (is_prime[i]) {\n primes.push_back(i);\n f...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n \n int n = 1e5;\n\n int total = r - l + 1;\n\n vector<bool>dp(n+1 , true);\n\n dp[0] = false;\n dp[1] = false;\n\n for(int i = 2 ; i <= sqrt(n) ; i++){\n if(dp[i]){ \...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n const long long MAX_SQUARE = 1e9 + 1;\n const int MAX_PRIME = 1e5;\n\n std::vector<long long> getPrimeSquares() {\n int max_limit = MAX_PRIME;\n std::vector<bool> is_prime(max_limit + 1, true);\n std::vector<long long> prime_squares;\n\n // S...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\n long long maxVal = 1e9;\n\n vector<long long> primeNum() {\n vector<bool> seive(1e5, true);\n seive[1] = false;\n seive[0] = false;\n\n vector<long long> isSpecial;\n\n for(long long i = 2; i < 1e5; i++) {\n if(seive[i] == true) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": " int mx=100001;\n vector<bool> isprime(mx, true);\n vector<int> primes;\n void sieve(){\n isprime[0]=isprime[1]=false;\n for(int i=2; i*i<=100000+1; i++){\n if(isprime[i]){\n for(int j=i*i; j<=100000+1; j+=i){\n isprime[j]=false;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\nvector<int> generatePrimes(int max) {\n vector<int>count ;\n vector<bool> isPrime(max + 1, true);\n isPrime[0] = isPrime[1] = false;\n for (int i = 2; i * i <= max; i++) {\n if (isPrime[i]) {\n for (int j = i * i; j <= max; j += i) {\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\nvector<pair<int,int>> prime_numbers = {{2,4},{3,9},{5,25},{7,49},{11,121},{13,169}};\nint v = 0;\nvoid function(int k) {\n if (k == 1) {\n return;\n }\nfor (int i = prime_numbers[prime_numbers.size()-1].first +2; i < 46340; i+=2) {\n bool not_prime = false;\n f...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Sieve {\npublic:\n vector<int> sieve; // isPrime or not\n vector<int> sumOfPFac; // sum of all prime factors (distinct)\n vector<int> noOfPFac; // no of prime factors\n vector<int> spm; // smallest prime multiple\n int n;\n\n Sieve(int n) {\n this->n = n;\n init();\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n \n bool *isprime;\n\n Solution(){\n \n isprime = new bool[100001];\n memset( isprime, true, sizeof( bool )*100001 );\n\n for(long long i = 2 ; i <= 100000 ; i++){\n \n if( isprime[i] and i*i <= 100000){\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\ntypedef long long ll;\n int nonSpecialCount(int l, int r) {\n bool *primes = new bool[1e5+1];\n for(ll i =0; i<1e5+1; i++) {\n primes[i] = true;\n }\n ll sqr = sqrt(1e5);\n primes[0] = false;\n primes[1] = false;\n for(ll p=2; p<=sqr; p++){\n if(primes[p]) {...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution\n{\nprivate:\n static constexpr auto upper_lim = 100000;\n\npublic:\n int nonSpecialCount(int l, int r)\n {\n std::vector<char> is_prime(upper_lim, true);\n is_prime[0] = is_prime[1] = false;\n\n auto spec = 0;\n\n for (auto i = 2; i < upper_lim && i * i ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "bool primes[100000001];\n#define ll long long\nclass Solution {\npublic:\n \n\n\n vector<ll> getPrimes(int n){\n for(int u=2;u*u <= n;u++){\n if(primes[u]) continue;\n\n else{\n primes[u] = false;\n for(int x = 2*u;x <= n;x += u){\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "typedef long long ll;\nconst ll NP = 1e7;\nbool prime[NP];\nll spf[NP];\nbool flag = false;\nvector<ll> p;\n\nvoid sieve() {\n fill(prime, prime + NP, true);\n for(ll i = 0; i < NP; i++) spf[i] = i;\n prime[0] = prime[1] = false;\n for(ll i = 2; i * i < NP; i++) {\n if(prime[i]) { \n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "#include <bits/stdc++.h>\nusing namespace std;\n\n#define ll long long int\n#define pb push_back\n#define pf push_front\n#define popf pop_front\n#define popb pop_back\n#define mkpr make_pair\n#define loop(i, k, n) for (ll i = k; i <= n; i++)\n#define roop(i, n, k) for (ll i = n; i >= k; i--)\n#define vi ve...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "#include <iostream>\n#include <vector>\n#include <cmath>\n#include <algorithm>\n\nclass Solution {\npublic:\n // Helper function to perform the Sieve of Eratosthenes\n std::vector<int> sieve(int n) {\n std::vector<bool> is_prime(n + 1, true);\n is_prime[0] = is_prime[1] = false;\n\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n bool isPrime(int n) {\n if(n == 1) return false;\n for(int i = 2; i * i <= n; i++) {\n if(n % i == 0) return false;\n }\n return true;\n }\n int nonSpecialCount(int l, int r) {\n set<int> sq;\n for(int i = (int)sqrt(l...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n map<int,int>prime;\n bool isPrime(int i){\n for(int j=2;j<=sqrt(i);j++){\n if(i%j==0)return false;\n }\n return true;\n }\n void primeTracker(int x,int y){\n prime[2]++;\n for(int i=max(x,3);i<=y;i++){\n if(isP...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\n bool check(int n)\n{\n \n if (n <= 1)\n return false;\n\n for (int i = 2; i <= n / 2; i++)\n if (n % i == 0)\n return false;\n\n return true;\n}\npublic:\n int nonSpecialCount(int l, int r) {\n map <long long,int> mp;\n int x = 1;\...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "\n\nclass Solution {\nprivate:\n int N=65537;\n vector<bool> a;\n vector<int> prime;\n vector<int> v;\n void initializePrimes(){\n if (a.size()) return;\n int m, n=N;\n a.assign(n,false);\n a[0]=a[1]=true;\n for(int i=0; i<=sqrt(n); i++){\n if(...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n bool isprime(int n)\n {\n for(int i=2;i<=sqrt(n);i++)\n {\n if(n%i == 0) return false ;\n }\n return true ;\n }\n int nonSpecialCount(int l, int r) {\n long long ans = r-l+1 ;\n vector<long long> v ;\n for(int ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n vector<int> f;\n for (int i = 2; i < 100000; ++i) {\n bool check = true;\n for (int j : f) {\n if (j * j > i) break;\n if (i % j == 0) {\n check = false;...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n vector<int> allPrime;\n void SieveOfEratosthenes(int n)\n {\n bool prime[n + 1];\n memset(prime, true, sizeof(prime));\n \n for (int p = 2; p * p <= n; p++) {\n if (prime[p] == true) {\n for (int i = p * p; i <= n; i...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "typedef long long ll;\nclass Solution {\npublic:\n bool isPrime[1000000];\n vector<int> primes;\n int nonSpecialCount(int l, int r) {\n\n memset(isPrime,true,sizeof(isPrime));\n for(ll v=2;v<100000;v++){\n if(isPrime[v]){\n primes.push_back(v);\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\nprivate:\n void sieve(vector<int>& primes){\n bitset<100001>b;\n b.set();\n for(long long i=2;i<=100000;i++){\n if(b[i]){\n primes.push_back(i);\n for(long j=i*i;j<=100000;j+=i){\n b[j]=false;\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n int nonSpecialCount(int l, int r) {\n vector<long> spl_num;\n int arr[50001];\n fill(arr, arr+50001, 1);\n // for(int i=0;i<10;i++) cout<<arr[i];\n arr[0]=arr[1]=0;\n for(long i=2;i<=50000;i++){\n if(arr[i]==1){\n ...
3,507
<p>You are given 2 <strong>positive</strong> integers <code>l</code> and <code>r</code>. For any number <code>x</code>, all positive divisors of <code>x</code> <em>except</em> <code>x</code> are called the <strong>proper divisors</strong> of <code>x</code>.</p> <p>A number is called <strong>special</strong> if it has ...
3
{ "code": "class Solution {\npublic:\n \n void primeCnt(vector<long long> &ans) {\n int n = 50000;\n int num[50000] = {0};\n \n for(int i = 2; i<n; i++) {\n if(num[i] == 0) {\n for(int j = 2*i; j<n; j+=i) {\n num[j] = 1;\n }...