QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#666620#2828. Algebraticking_awayAC ✓316ms4272kbC++206.2kb2024-10-22 19:23:592024-10-22 19:24:08

Judging History

你现在查看的是最新测评结果

  • [2024-10-22 19:24:08]
  • 评测
  • 测评结果:AC
  • 用时:316ms
  • 内存:4272kb
  • [2024-10-22 19:23:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ui = unsigned int;
using ull = unsigned long long;
using ll = long long;
#define endl '\n'
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int maxn = 2e5 + 10;
const int mod = 1000000007;
#define inl inline
#define fr(i, a, b) for (int i = a; i <= b; i++)
#define ford(i, a, b) for (int i = a; i >= b; i--)
#define forall(i, a) for (auto &i : a)

/**
   ____         ___ _____
  / ___| _   _ / _ \___ /
  \___ \| | | | | | ||_ \
   ___) | |_| | |_| |__) |
  |____/ \__, |\___/____/
         |___/
*/
istream &operator>>(istream &in, vector<int> &v)
{
    for (auto &i : v)
        in >> i;
    return in;
}
ostream &operator<<(ostream &out, vector<int> &v)
{
    for (auto &i : v)
        out << i << " ";
    return out;
}
bool _output = 0;

#define int ll
void solve(int n, int m, int k)
{
    if (k > n)
    {
        cout << 0 << endl;
        return;
    }
    if (n == 1)
    {
        int ans = 0;
        if (k == 1)
        {
            ans = (2 * m + 1) * 2 * m;
        }
        cout << ans << endl;
        return;
    }
    else if (n == 2)
    {
        int ans = 0;
        if (k > 2)
        {
            cout << ans << endl;
            return;
        }
        else
        {
            if (k == 1)
            {
                int ans1 = 0;
                for (int i = -m; i <= m; i++)
                {
                    int a = i * i;
                    if (a > 4 * m)
                        continue;
                    if (a % 4 == 0)
                        ans1++;
                }
                cout << ans1 << endl;
                return;
            }
            if (k == 2)
            {
                int ans2 = 0;
                for (int i = 0; i <= m; i++)
                {
                    int a = i * i;
                    for (int j = i; j >= 1; j--)
                    {
                        int b = a - j * j;
                        if (b > 4 * m)
                            break;
                        if (b % 4 == 0)
                        {
                            ans2++;
                            if (i)
                                ans2++;
                        }
                    }
                    for (int j = i + 1;; j++)
                    {
                        int b = j * j - a;
                        if (b > 4 * m)
                            break;
                        if (b % 4 == 0)
                        {
                            ans2++;
                            if (i)
                                ans2++;
                        }
                    }
                }
                cout << ans2 << endl;
            }
        }
        return;
    }
    // n > 3
    auto qsm = [&](int a, int b)
    {
        int ans = 1;
        while (b)
        {
            if (b & 1)
            {
                using i64 = __int128_t;
                if ((i64)((i64)ans * a) > 1e18)
                {
                    return -1ll;
                }
                ans = ans * a;
                if ((i64)((i64)ans) > 1e18)
                {
                    return -1ll;
                }
            }
			using i64 = __int128_t;
			if ((i64)((i64)a * a) > 1e18)
            {
                return -1ll;
            }
            a = a * a;
            if ((i64)((i64)a) > 1e18)
            {
                return -1ll;
            }
            b >>= 1;
        }
        return ans;
    };
    int mx = 0;
    for (int x = 0;; x++)
    {
        if (qsm(x, n) == -1ll)
            break;
        if (qsm(x, n) > m * x + m)
        {
            break;
        }
        mx = x;
    }
    int ans = 0;
    auto make = [&](int a, int b)
    {
        return a * (int)(2e6) + b;
    };
    unordered_map<int, int> mp;
    for(int x1=-mx;x1<=mx;x1++)
    {
    	for(int x2=-mx;x2<x1;x2++)
    	{
    		int qss1 = qsm(x1, n);
    		int qss2 = qsm(x2, n);
    		int a=(qss1-qss2)%(x2-x1);
    		if(a!=0)
    		{
    			continue;
			}
			int b=(x1*qss2-x2*qss1)%(x2-x1);
			if(b!=0)
    		{
    			continue;
			}
			a=(qss1-qss2)/(x2-x1);
			b=(x1*qss2-x2*qss1)/(x2-x1);
			if (abs(a) <= m && abs(b) <= m)
            {
            	//cout<<a<<" "<<b<<endl;
            	if(mp[make(a, b)]==2&&k==2)
            	{
            		ans--;
				}
                mp[make(a, b)]+=2;
                if(mp[make(a, b)]==2&&k==2)
            	{
            		ans++;
				}
				if(mp[make(a, b)]==4&&k==3)
            	{
            		ans++;
				}
                mp[make(a, b)]=min(mp[make(a, b)],3ll);
            }
		}
	}
    for (int x = 1; x <= mx; x++)
    {
        int qss = qsm(x, n);
        int l = (-m - qss) / x;
        int r = (m - qss) / x;
        if (l > r)
            swap(l, r);
        for (int a = l; a <= r; a++)
        {
            // unordered_map<int, int> mp;
            int b = -a * x - qss;

            if (abs(a) <= m && abs(b) <= m)
            {
            	if(!mp.count(make(a, b))&&k==1)
            	{
            		ans++;
				}
            }
        }
        x=0-x;
        if(n&1) qss=0-qss;
        l = (-m - qss) / x;
        r = (m - qss) / x;
        if (l > r)
            swap(l, r);
        for (int a = l; a <= r; a++)
        {

            // unordered_map<int, int> mp;
            int b = -a * x - qss;

            // if(a==-1&&b==0) cout<<"! "<<endl;
            if (abs(a) <= m && abs(b) <= m)
            {
                if(!mp.count(make(a, b))&&k==1)
            	{
            		ans++;
				}
            }
        }
        x=0-x;
    }
    int x = 0;
    for (int a = -m; a <= m; a++)
    {
        // unordered_map<int, int> mp;
        int b = 0;
        if (abs(a) <= m)
        {
            if(!mp.count(make(a, b))&&k==1)
            {
            	ans++;
			}
        }
    }

    cout << ans << endl;
    //cout<<mp.size();
}
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, m, k;
    while(cin >> n >> m >> k)
    {
    	solve(n, m, k);
	}
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3508kb

input:

2 1 1
2 2 2
3 3 3

output:

1
7
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 15ms
memory: 3568kb

input:

1 1 1
1 2 1
1 3 1
1 4 1
1 5 1
1 6 1
1 7 1
1 8 1
1 9 1
1 10 1
1 11 1
1 12 1
1 13 1
1 14 1
1 15 1
1 16 1
1 17 1
1 18 1
1 19 1
1 20 1
1 21 1
1 22 1
1 23 1
1 24 1
1 25 1
1 26 1
1 27 1
1 28 1
1 29 1
1 30 1
1 31 1
1 32 1
1 33 1
1 34 1
1 35 1
1 36 1
1 37 1
1 38 1
1 39 1
1 40 1
1 41 1
1 42 1
1 43 1
1 44 1
1...

output:

6
20
42
72
110
156
210
272
342
420
506
600
702
812
930
1056
1190
1332
1482
1640
1806
1980
2162
2352
2550
2756
2970
3192
3422
3660
3906
4160
4422
4692
4970
5256
5550
5852
6162
6480
6806
7140
7482
7832
8190
8556
8930
9312
9702
10100
10506
10920
11342
11772
12210
12656
13110
13572
14042
14520
15006
155...

result:

ok 9801 lines

Test #3:

score: 0
Accepted
time: 18ms
memory: 3668kb

input:

1 1 2
1 2 2
1 3 2
1 4 2
1 5 2
1 6 2
1 7 2
1 8 2
1 9 2
1 10 2
1 11 2
1 12 2
1 13 2
1 14 2
1 15 2
1 16 2
1 17 2
1 18 2
1 19 2
1 20 2
1 21 2
1 22 2
1 23 2
1 24 2
1 25 2
1 26 2
1 27 2
1 28 2
1 29 2
1 30 2
1 31 2
1 32 2
1 33 2
1 34 2
1 35 2
1 36 2
1 37 2
1 38 2
1 39 2
1 40 2
1 41 2
1 42 2
1 43 2
1 44 2
1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
3
7
13
20
26
36
42
52
59
69
75
89
95
105
115
126
132
146
152
166
176
186
192
210
217
227
237
251
257
2...

result:

ok 9801 lines

Test #4:

score: 0
Accepted
time: 18ms
memory: 3608kb

input:

1 1 3
1 2 3
1 3 3
1 4 3
1 5 3
1 6 3
1 7 3
1 8 3
1 9 3
1 10 3
1 11 3
1 12 3
1 13 3
1 14 3
1 15 3
1 16 3
1 17 3
1 18 3
1 19 3
1 20 3
1 21 3
1 22 3
1 23 3
1 24 3
1 25 3
1 26 3
1 27 3
1 28 3
1 29 3
1 30 3
1 31 3
1 32 3
1 33 3
1 34 3
1 35 3
1 36 3
1 37 3
1 38 3
1 39 3
1 40 3
1 41 3
1 42 3
1 43 3
1 44 3
1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 9801 lines

Test #5:

score: 0
Accepted
time: 17ms
memory: 3864kb

input:

1 1 4
1 2 4
1 3 4
1 4 4
1 5 4
1 6 4
1 7 4
1 8 4
1 9 4
1 10 4
1 11 4
1 12 4
1 13 4
1 14 4
1 15 4
1 16 4
1 17 4
1 18 4
1 19 4
1 20 4
1 21 4
1 22 4
1 23 4
1 24 4
1 25 4
1 26 4
1 27 4
1 28 4
1 29 4
1 30 4
1 31 4
1 32 4
1 33 4
1 34 4
1 35 4
1 36 4
1 37 4
1 38 4
1 39 4
1 40 4
1 41 4
1 42 4
1 43 4
1 44 4
1...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 9801 lines

Test #6:

score: 0
Accepted
time: 2ms
memory: 3604kb

input:

1 1 100
1 2 100
1 3 100
1 4 100
1 5 100
1 6 100
1 7 100
1 8 100
1 9 100
1 10 100
1 11 100
1 12 100
1 13 100
1 14 100
1 15 100
1 16 100
1 17 100
1 18 100
1 19 100
1 20 100
1 21 100
1 22 100
1 23 100
1 24 100
1 25 100
1 26 100
1 27 100
1 28 100
1 29 100
1 30 100
1 31 100
1 32 100
1 33 100
1 34 100
1 3...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 9801 lines

Test #7:

score: 0
Accepted
time: 2ms
memory: 3516kb

input:

1 1 500000
1 2 500000
1 3 500000
1 4 500000
1 5 500000
1 6 500000
1 7 500000
1 8 500000
1 9 500000
1 10 500000
1 11 500000
1 12 500000
1 13 500000
1 14 500000
1 15 500000
1 16 500000
1 17 500000
1 18 500000
1 19 500000
1 20 500000
1 21 500000
1 22 500000
1 23 500000
1 24 500000
1 25 500000
1 26 5000...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 9801 lines

Test #8:

score: 0
Accepted
time: 11ms
memory: 3868kb

input:

578 237 1
713 995 1
335 454 1
640 374 1
718 942 1
924 478 1
783 694 1
530 793 1
368 502 1
829 291 1
26 32 1
335 212 1
668 98 1
856 793 1
195 958 1
748 337 1
636 73 1
771 608 1
290 152 1
536 945 1
406 436 1
240 85 1
673 849 1
178 951 1
595 462 1
285 105 1
972 369 1
575 295 1
484 149 1
860 903 1
641 1...

output:

1417
5968
2722
2239
5647
2863
4162
4753
3007
1744
187
1270
583
4753
5746
2017
433
3646
907
5665
2611
505
5092
5701
2770
628
2209
1768
889
5413
874
4807
1144
4045
355
439
5764
2269
5665
4576
979
4591
5287
1090
5419
4885
4237
1216
3121
4204
559
3904
3526
2368
2515
3424
3868
3691
4621
196
5176
4579
178...

result:

ok 996 lines

Test #9:

score: 0
Accepted
time: 11ms
memory: 3836kb

input:

203 885 2
132 672 2
671 241 2
919 476 2
961 866 2
557 937 2
517 834 2
883 978 2
367 370 2
298 167 2
554 463 2
666 921 2
416 249 2
414 587 2
426 517 2
605 207 2
115 766 2
495 375 2
755 573 2
336 884 2
936 419 2
968 412 2
14 553 2
284 785 2
219 558 2
746 307 2
100 715 2
782 61 2
106 525 2
87 731 2
830...

output:

0
3
0
0
0
0
0
0
0
3
3
3
3
3
3
0
0
0
0
3
3
3
3
3
0
3
3
3
3
0
3
0
0
3
0
0
3
3
0
3
3
0
3
0
3
0
0
0
0
0
0
3
3
0
0
0
3
3
3
0
3
3
0
0
3
0
3
0
3
3
0
0
3
3
0
3
3
3
3
0
0
0
3
3
3
3
0
3
0
3
0
3
3
3
3
3
0
3
3
0
0
0
0
3
3
0
3
0
3
0
0
0
3
0
3
0
0
0
3
0
3
3
0
0
0
0
3
3
0
0
0
0
3
3
3
3
0
0
3
0
0
0
10
0
3
0
0
0
3
0...

result:

ok 994 lines

Test #10:

score: 0
Accepted
time: 5ms
memory: 3820kb

input:

680 533 3
409 269 3
145 902 3
213 221 3
439 870 3
566 834 3
239 974 3
105 163 3
202 676 3
484 604 3
946 689 3
911 988 3
236 836 3
842 943 3
950 200 3
21 77 3
178 380 3
940 61 3
449 869 3
368 305 3
701 964 3
915 738 3
472 739 3
163 137 3
794 93 3
337 991 3
663 63 3
481 390 3
59 901 3
249 433 3
327 15...

output:

0
1
1
1
1
0
1
1
0
0
0
1
0
0
0
1
0
0
1
0
1
1
0
1
0
1
1
1
1
1
1
1
0
0
1
1
0
0
0
0
1
1
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
1
1
1
0
1
1
1
0
0
0
1
1
1
0
0
0
0
0
1
0
1
1
0
0
0
0
1
1
0
0
0
1
1
0
0
0
1
0
1
0
1
1
0
0
1
0
0
1
1
0
1
1
1
0
0
0
1
0
0
0
0
0
1
0
0
0
1
1
0
1
1
0
1
1
0
1
1
0
0
1
1
0
1
0
0
1
1
0
0
1
0
1
...

result:

ok 988 lines

Test #11:

score: 0
Accepted
time: 9ms
memory: 3632kb

input:

240363 277116 2
97128 25738 2
314633 50385 2
16721 95992 2
140375 28183 2
75271 6448 2
354012 11998 2
20088 3953 2
1095 99 2
33619 45 2
399698 32 2
395408 5 2
86410 6 2

output:

0
3
0
0
0
0
3
3
0
0
3
3
3

result:

ok 13 lines

Test #12:

score: 0
Accepted
time: 10ms
memory: 3860kb

input:

43764 458932 3
475378 11851 3
302405 25039 3
475095 505 3
144912 51 3
166449 351 3
134516 1768 3
349953 807 3
425147 239 3
116238 285 3
373794 99 3
305801 1 3
465817 32 3
167314 4 3
441446 4 3
309241 8 3
462352 8 3
452008 14 3
410841 1 3
195328 1 3

output:

0
0
1
1
0
1
0
1
1
0
0
1
1
0
0
1
0
0
1
0

result:

ok 20 lines

Test #13:

score: 0
Accepted
time: 9ms
memory: 3604kb

input:

208927 82695 10
480469 112188 10
159347 123242 10
209065 63110 10
251159 45081 10
426688 45862 10
27958 18684 10
332091 4883 10
123690 1286 10
287322 575 10
135302 1671 10
308539 450 10
296918 53 10
448480 207 10
334244 2 10
122933 1 10
373597 2 10
329552 2 10
371316 1 10
219194 3 10
117509 1 10
147...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 22 lines

Test #14:

score: 0
Accepted
time: 9ms
memory: 3796kb

input:

21139 219315 5000
486799 146895 5000
11917 27333 5000
437401 104559 5000
336669 954 5000
7873 572 5000
414204 150 5000
436939 105 5000
188387 52 5000
445845 15 5000
316389 32 5000
289763 12 5000
189983 4 5000
414712 1 5000
243662 1 5000

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 15 lines

Test #15:

score: 0
Accepted
time: 9ms
memory: 3860kb

input:

176736 412451 1

output:

2474701

result:

ok single line: '2474701'

Test #16:

score: 0
Accepted
time: 14ms
memory: 3856kb

input:

2 500000 2

output:

14276189

result:

ok single line: '14276189'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3568kb

input:

2 499999 3

output:

0

result:

ok single line: '0'

Test #18:

score: 0
Accepted
time: 316ms
memory: 4272kb

input:

3 500000 2

output:

124

result:

ok single line: '124'

Test #19:

score: 0
Accepted
time: 316ms
memory: 4112kb

input:

3 499999 3

output:

15279

result:

ok single line: '15279'

Test #20:

score: 0
Accepted
time: 112ms
memory: 3716kb

input:

4 500000 2

output:

2538

result:

ok single line: '2538'

Test #21:

score: 0
Accepted
time: 111ms
memory: 3692kb

input:

4 499999 3

output:

0

result:

ok single line: '0'

Test #22:

score: 0
Accepted
time: 7ms
memory: 3564kb

input:

500000 499999 2

output:

3

result:

ok single line: '3'

Test #23:

score: 0
Accepted
time: 10ms
memory: 3516kb

input:

500000 499999 3

output:

0

result:

ok single line: '0'