Sample input
11 10
Sample Output
10 5 7 5 8 3 9 5 7 4 10
(Hee hee hee, only to get help several dalao know, you must be in memory of)
This question is the use of inclusion and exclusion ah
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 100005; int n, prime[N], tot, cnt; bool vis[N]; ll m, num[N], ans; void getprime() { for (int i = 2; i <= n; i++) { if (!vis[i]) prime[++tot] = i; for (int j = 1; j <= tot && i * prime[j] <= n; j++) { vis[i * prime[j]] = true; if (i % prime[j] == 0) break; } } } void work(int n) { for (int i = 1; i <= tot && prime[i] <= n; i++) { int x = prime[i]; if (n % x == 0) { num[++cnt] = x;// while (n % x == 0) n /= x; } } } // lose its not relatively prime, the rest is prime to the number of friends // not prime to gnaw cut it, looking for his prime factors of myself, equally sure that he's not prime factors of prime to friends void DFS ( int A, int p, int S) { // number p approximately, s is a positive or negative (plus or minus) IF (! A) { ANS + = (LL) * S m / p; // m / p m is the number of a multiple of p in return ; } // see the number of prime factors, a -> plus, two -> Save, three -> plus ... DFS (a - . 1 , p, S ); DFS (A - 1 , * P NUM [A], - 1 * S); / * For example, there factor 3,4,5 1 / \ / \ . 3. 1 / \ / \ . 3 *. 4. 3. 4. 1 / \ / \ / \ / \ . 3 *. 4 *. 5. 3 *. 4. 3 *. 5. 3. 4 *. 5. 4. 5. 1 * / } Signed main () { CIN > > >> n- m; getprime (); // prime table for ( int I = . 1 ; I <= n-; I ++ ) { ANS = 0 ; CNT = 0 ; // quality factor number Work (I); // seeking the number of prime factors of i DFS (CNT, . 1 , . 1 ); printf("%lld\n", ans); } }