Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream in("cufar.in");
  7. ofstream out("cufar.out");
  8.  
  9. int n, p, ciur[1000001], x, maxim, prime[1000001], k;
  10. long long S;
  11. pair<int, int> v[1000001];
  12.  
  13. void find_prime(){
  14. ciur[0] = 1;
  15. ciur[1] = 1;
  16. for(int i = 2; i<=maxim; i++){
  17. if(ciur[i] == 0){
  18. prime[++k] = i;
  19. for(int j = 2; i * j <=maxim; j++)
  20. ciur[i*j] = 1;
  21. }
  22. }
  23. }
  24.  
  25. int main(){
  26. in >> p >> n;
  27. for(int i = 1; i<=n; i++){
  28. in >> v[i].first >> v[i].second;
  29. if(v[i].first > maxim) maxim = v[i].first;
  30. }
  31. find_prime();
  32. for(int i = 1; i<=n; i++){
  33. int aux = 0;
  34. int j = 1;
  35. for(j; j<=v[i].first && aux!=v[i].second; j++)
  36. if(v[i].first % prime[j] == 0) aux++;
  37. if(aux == v[i].second && p == 1) out << prime[j-1] << endl;
  38. else S+=prime[j-1];
  39. }
  40. if(p == 2) out << S;
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement