Number Theory (updating)

1. Divide

"True" example: Luogu 3518

Problem solution: First, combined with Pei Shu's theorem, it can be concluded that gcd(x,n) and gcd(x,y) are both passwords, and then all passwords can be obtained from 1 to n/x times of x (x is gcd(a[k ],n) the smallest factor that does not divide a[1]~a[k-1]), because the number of factors is small, it can be violently screened, ans=n/x.

 1 #include <bits/stdc++.h>
 2 #define int long long
 3 
 4 using namespace std;
 5 
 6 const int len = 3e5;
 7 int n,k,ans,a[len];
 8 
 9 inline bool cmp(int x) {
10     for (int i=1;i<k;i++) if (a[i]%x == 0) return false;
11     return true;
12 }
13 
14 signed main() {
15     ios :: sync_with_stdio(0);
16     cin >> n >> k;
17     for (int i=1;i<=k;i++) cin >> a[i];
18     a[k] = __gcd(a[k],n);
19     for (int i=1;i*i<=a[k];i++) {
20         if (a[k]%i==0 && cmp(i)) {
21             cout << n/i << endl;
22             return 0;
23         }
24         else if (a[k]%i==0 && cmp(a[k]/i)) {
25             ans = n/(a[k]/i);
26         }
27     }
28     cout << ans << endl;
29     return 0;
30 }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325783367&siteId=291194637