i want u to act as the most skilled competetive programmer, u take time to think and…
- User
i want u to act as the most skilled competetive programmer, u take time to think and check if ur solution works and match up with the example tescase, u need to think thoroughly since u r in a contest. use need to use this template, make sure u have lowercase rlly short variable names and NO COMMENTS (in the code, at all) and since ur using this template always use int and not long long: #include <bits/stdc++.h> #define int long long using namespace std;
signed main() { cin.tie(0); ios_base::sync_with_stdio(false);
Time Limit: 4 sec / Memory Limit: 1024 MB
Score : 650 points
Problem Statement We call a positive integer n a good integer if and only if the sum of its positive divisors is divisible by 3. You are given two positive integers N and M. Find the number, modulo 998244353, of length- M sequences A of positive integers such that the product of the elements in A is a good integer not exceeding N.
Constraints 1≤N≤10 10
1≤M≤10 5
N and M are integers. Input The input is given from Standard Input in the following format:
N M Output Print the answer.
Sample Input 1 Copy 10 1 Sample Output 1 Copy 5 There are five sequences that satisfy the conditions:
(2) (5) (6) (8) (10) Sample Input 2 Copy 4 2 Sample Output 2 Copy 2 There are two sequences that satisfy the conditions:
(1,2) (2,1) Sample Input 3 Copy 370 907 Sample Output 3 Copy 221764640 Sample Input 4 Copy 10000000000 100000 Sample Output 4 Copy 447456146
MAKE SURE UR CODE MATCHES WITH SAMPLE TESTCASES OTHERWISE, DO ANOTHER APPROACH.
- Assistant
#include <bits/stdc++.h> #define int long long using namespace std; const int MOD = 998244353; int inv_max = 100034; int inv_arr[100035]; int N, M; // Function to compute a^b mod MOD int power_pow(int a, int b){ int res=1; a %= MOD; while(b>0){ if(b&1) res = res * a % MOD; a = a * a % MOD; b >>=1; } return res; } // Function to compute combination C(M + e -1, e) mod MOD int comb(int M_val, int e){ if(e ==0) return 1; int res=1; for(int i=1;i<=e;i++){ res = res * (M_val + i -1) % MOD; res = res * inv_arr[i] % MOD; } return res; } int ans=0; // List of primes up to sqrt(1e10) ~1e5 vector<int> sieve_primes(){ int limit = 100000; vector<bool> is_prime(limit+1, true); is_prime[0]=is_prime[1]=false; for(int i=2;i<=limit;i++) { if(is_prime[i]){ for(int j=2*i;j<=limit;j+=i) is_prime[j]=false; } } vector<int> primes; for(int i=2;i<=limit;i++) if(is_prime[i]) primes.push_back(i); return primes; } vector<int> primes; // DFS to enumerate 'good' numbers and accumulate the answer void dfs(int idx, int P, bool flag1, bool flag2){ if(idx == primes.size()){ if(flag1 || flag2){ ans = (ans + 1) % MOD; } return; } int p = primes[idx]; if(p > N) { if(flag1 || flag2){ ans = (ans + 1) % MOD; } return; } int e=0; while(true){ if(P > N) break; bool new_f1 = flag1; bool new_f2 = flag2; if(p %3 ==1 && e %3 ==2) new_f1 = true; if(p %3 ==2 && e %2 ==1) new_f2 = true; dfs(idx+1, P, new_f1, new_f2); if(P > N / p) break; P *= p; e++; } } signed main() { cin.tie(0); ios_base::sync_with_stdio(false); cin >> N >> M; // Precompute inverses for(int i=1;i<=inv_max;i++) inv_arr[i] = power_pow(i, MOD-2); // Get primes primes = sieve_primes(); // Start DFS dfs(0, 1, false, false); cout << ans; }