数论(updating)

1、整除

“真”例题:洛谷3518

题解:首先结合裴蜀定理得出gcd(x,n)和gcd(x,y)均为密码,然后即可得出所有密码为x的1至n/x倍(x为gcd(a[k],n)的最小的不整除a[1]~a[k-1]的因子),因为因子数不多可以暴力筛选,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 }

猜你喜欢

转载自www.cnblogs.com/yewt01/p/9005487.html