fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. vector<bool>isPrime;
  5. void seive(int n){
  6. isPrime.resize(n+1,true);
  7. isPrime[0] = isPrime[1] = false;
  8. for(int i = 2 ; i < n ;i++ ){
  9. if(isPrime[i]){
  10. for(int j = i*i ; j < n ;j+=i){
  11. isPrime[j]=false;
  12. }
  13. }
  14. }
  15. }
  16. int main() {
  17. int n;
  18. cin>>n;
  19. seive(n);
  20. int p;
  21. for(int i = n-1 ; i>=0 ;i--){
  22. if(isPrime[i]){
  23. p = i;
  24. break;
  25. }
  26. }
  27. cout<<"p: "<<p <<endl;
  28. ll d = 1LL*p*n;
  29. cout<<"d : " <<d <<endl;
  30. ll ans = 0;
  31. if(d%2 == 0)ans = d/2;
  32. else ans =((n-1)*p+2)/2;
  33.  
  34. cout<<ans;
  35. }
Success #stdin #stdout 0s 5320KB
stdin
7
stdout
p: 5
d : 35
16