|
|
I pass this problem with Sieve of Eratosthenes, but i think solution with Pollard's rho algorithm is funnier, and wrote it too. If you cant pass it with this algo just use all prime modules from 1'000'000'007 to 1'000'001'393. Did you check small dividers? ro pollard works very poorly with them If TL let me check all with O(sqrt(n)), I do it. I invoke rho pollard only if can not pass test with O(sqrt(n)) Test 47 is some number from 1e14 to 1e18 with correct answer "No". Please add the following testcase: 869637034218881024 = 2^18 * 1806487 * 1836383 The answer should be "Yes". My solution prints "No" and nevertheless has AC. Thank you! Good test. I found another good one. 999979520100663296. I think it's stronger. However I got AC before, but i was looking for a good test. Edited by author 29.10.2019 00:37 One of the largest allowed numbers 999999999987679232 = 2^19 * 1907348632789 where the second multiplier is a prime number. Check 524288, should be NO. Test other cases where you have 19 factors, and the last one remaining is 1. who has ideas, what test it is? Help please: Test 23, whats wrong, what test should chek? def sieve(n): lis = list(range(n + 1)) lis[1] = 0 for i in lis: if i > 1: for j in range(i + i, len(lis), i): lis[j] = 0 return [i for i in lis if i != 0] c = sieve(200) a = int(input()) if a == 0: print('No') i = 0 b = [] e = 0 while a != 1: if a%5 != 0 and a%2 != 0 and a%3 != 0: e +=1 break elif a % c[i] == 0: a /= c[i] b.append(c[i]) continue else: i += 1 d = str(len(b)) if len (b) == 20 or (len (b) == 19 and e != 0): print('Yes') else: print('No') In this code possible i > len(c) 24303989349327424 = 2^6 * 11^14 (Yes) 79792266297612001 = 7^20 (Yes) 467851794974552912 = 7^1 * 2^4 * 11^15 (Yes) 566608619280937216 = 2^8 * 19^12 (Yes) 932195579567617600 = 5^2 * 2^6 * 17^12 (Yes) 999983616067108864 = 1953109^2 * 2^18 (Yes) 999197664639844352 = 19681^3 * 2^17 (Yes) 998848442311376896 = 15619^3 * 2^18 (No) 999999999987679232 = 1907348632789^1 * 2^19 (Yes) 798352691495399040 = 2^7 * 3^1 * 5^1 * 7^1 * 11^1 * 13^1 * 17^1 * 19^1 * 23^1 * 29^1 * 31^1 * 37^1 * 41^2 (Yes) I thought that using the sieve of Eratosthenes would slow down the program, but it turned out the opposite. Edited by author 05.11.2020 03:23 Edited by author 05.11.2020 03:23 Edited by author 05.11.2020 03:23 Edited by author 29.05.2020 13:26 Edited by author 29.05.2020 13:26 Try to change this for (int i = 3; i <= Convert.ToInt32(Math.Ceiling(BigInteger.Log(n, 2))); i += 2) to this for (BigInteger i = 3; i * i <= n; i += 2) Btw, you do not need BigInteger here, long is enough. Edited by author 30.05.2020 21:39 After this you will receive TLE39, try to handle the case with two big multiplied prime numbers, for example 1000000007*1000000009. Edit: this is even easier, than I thought. Just change your for to for (BigInteger i = 3; i < 10000000; i += 2) Edited by author 29.05.2020 03:42 Edited by author 29.05.2020 03:42 i got TLE 21 I was able to reach 28 test in Python 3. Я дошел до 28 теста на Python 3. Edited by author 24.11.2016 23:52 Yes, I solved this problem using Python Yes, you just have to do some optimizations I get TLE on 22 test. What can you advise? 1)In solution you must find all primes <= 10^7. 2)You must use that n<=10^18. 1. find all primes up to 2 millions 2. if remainder > 2 millions, check if it is a prime Why do you take this number? big number N = X*Y*(p1*p2*p3*....*p18) = X*Y*(A) A = at least 2^18 = 262144 So, X*Y = at most 10^18 / 2^18 = 3 814 697 266 000 So either X or Y is less than 10^7 Edited by author 05.11.2019 20:56 Edited by author 05.11.2019 20:57 Can someone provide a test, that makes the following code get TLE? // ITNOA #include<bits/stdc++.h> using namespace std; #define ll long long int main() { ll n; cin >> n; int cnt = 0; for (ll i = 2;i*i <= min((ll)1e18, n);i++) while (n%i == 0) { n /= i; cnt++; } if (n > 1) cnt++; if (cnt == 20) cout << "Yes\n"; else cout << "No\n"; } 2^19 or another where factorized number = 19 0.436 seconds, 6840 kb just go to google and type there: monte carlo factorization --- this algo is O(N^1/4), so its O(1e4 * sqrt(2)) Please help me. TLE #39 EDIT: GOT AC how The least prime divider in tests is less than 1.1E6 (but checking till 8E7 will still got AC) 1) Find the prime numbers up to 10,000,100 (Sieve of Eratosthenes) 2) if the sum is equal to 19 degrees, then the residue is prime to check What can you advise? 1) Up to 10M? 2M is enough. sqrt( 10^18 / 2^18) ~= 1.5M 2) "Yes" precondition: N > 1 "Yes" condition: sum is 20 and residue is 1 "Yes" condition: sum is 19 and residue>1 and residue is prime Could you show please code? AC Edited by author 09.03.2017 18:16 > if (kol == 20){ It's suspicious a bit. Please try test (2^20)*3, expected answer is No 3145728 No 20^20 * 3^1 sum 21 if I understand condition of the problem: 3^1*5^1*7^2*11^1*17^12*23^3 answer is "Yes" ? Edited by author 01.03.2017 13:26 |
|
|