-
Notifications
You must be signed in to change notification settings - Fork 0
/
C. Physical Education Lesson.cpp
72 lines (44 loc) · 1.84 KB
/
C. Physical Education Lesson.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 998244353
int main()
{
int t;
cin >> t;
while (t--) {
ll n,x;cin>>n>>x;
ll ans=0;
for (ll i =1; i*i <=(n-x); i++)
{
if((n-x)%i==0){
if(i%2==0 and (i+2)/2>=x){
ans++;
}
if(n-x!=i*i and ((n-x)/i)%2==0 and ((n-x)/i + 2)/2>=x){
ans++;
}
}
}
for (ll i = 1;x!=1 and i*i <=(n+x-2); i++)
{
if((n+x-2)%i==0){
if(i%2==0 and (i+2)/2>x) ans++;
if( (n+x-2) != i*i and ((n + x - 2)/i) % 2 == 0 and ((n+x-2)/i + 2)/2>x){
ans++;
}
}
}
cout<<ans<<endl;
}
}
/*
All numbers repeat every 2k - 2 positions. If the boy Vasya's number is calculated to be x, then it can be at positions of the form
(2k - 2) · t + x, or (2k - 2) · t + k + k -x, for some non-negative t. This is true for all x, except for x = 1 and x = k ~--- for
these values, there is only one option left.
Let's fix one of the options, the second one will be analogous. We need to find how many different values of k satisfy the equation
(2k-2). t+ x = n, for some non-negative t. It is not difficult to see that this holds if and only if n - x is divisible by 2k - 2.
Therefore, it is necessary to find the number of textbf{even} divisors of the number n - x. To consider the second case, it is necessary
to proceed similarly with the number n + x - 2.
In this problem-solving scenario, we observe that numbers repeat every 2k - 2 positions, except for x = 1 and x = k, where there's only one option. By fixing one option, we find the number of even divisors of n - x and n + x - 2, respectively, to determine the valid values of k. This approach, leveraging the properties of divisors, enables us to efficiently solve the problem. 💡🔍
*/