File tree Expand file tree Collapse file tree 2 files changed +98
-0
lines changed
Codeforces/After Placement Expand file tree Collapse file tree 2 files changed +98
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ #include < bits/stdc++.h>
6+ using namespace std ;
7+ typedef long long ll;
8+
9+
10+ int solve (){
11+ int n;
12+ cin >> n;
13+ bool ok = true ;
14+ for (int i = 1 ; i <= n; i++)
15+ {
16+ int x;
17+ cin >> x;
18+ bool found = false ;
19+ for (int j = i + 1 ; j >= 2 ; j--)
20+ {
21+ if (x % j)
22+ {
23+ found = true ;
24+ break ;
25+ }
26+ }
27+ ok &= found;
28+ }
29+ if (ok)
30+ {
31+ cout << " YES\n " ;
32+ }
33+ else
34+ {
35+ cout << " NO\n " ;
36+ }
37+ return 0 ;
38+ }
39+ int main ()
40+ {
41+ int testCase=1 ;
42+ cin>>testCase;
43+ while (testCase--){
44+ solve ();
45+ }
46+ return 0 ;
47+ }
Original file line number Diff line number Diff line change 1+ /*
2+ written by Pankaj Kumar.
3+ country:-INDIA
4+ */
5+ typedef long long ll ;
6+ const ll INF=1e18 ;
7+ const ll mod1=1e9 +7 ;
8+ const ll mod2=998244353 ;
9+ // Add main code here
10+
11+ class Solution
12+ {
13+ public:
14+ vector<vector<int >> threeSum (vector<int > &nums)
15+ {
16+ sort (nums.begin (), nums.end ());
17+ vector<vector<int >> res;
18+ int n = nums.size ();
19+
20+ for (int i = 0 ; i < n; i++)
21+ {
22+ if (i > 0 && nums[i] == nums[i - 1 ])
23+ continue ;
24+ int j = i + 1 , k = n - 1 ;
25+ while (j < k)
26+ {
27+ int sum = nums[i] + nums[j] + nums[k];
28+ if (sum == 0 )
29+ {
30+ res.push_back ({nums[i], nums[j], nums[k]});
31+ while (j < k && nums[j] == nums[j + 1 ])
32+ j++;
33+ while (j < k && nums[k] == nums[k - 1 ])
34+ k--;
35+ j++;
36+ k--;
37+ }
38+ else if (sum < 0 )
39+ {
40+ j++;
41+ }
42+ else
43+ {
44+ k--;
45+ }
46+ }
47+ }
48+
49+ return res;
50+ }
51+ };
You can’t perform that action at this time.
0 commit comments