Advertisement
semsem_elazazy

F. Equation

Feb 18th, 2022
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.43 KB | None | 0 0
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #define ll long long
  4. using namespace std;
  5.  
  6. void equation (int x, int n)
  7. {
  8.    int sum=0;
  9.    if (x== 0 )  cout<<-1;  
  10.    else{
  11.     for(int i=2 ; i<=n ; i+=2){
  12.       sum+=pow(x, i);    
  13.     }
  14.      cout<<sum;
  15.     }
  16. }
  17.  
  18. int main() {
  19.    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  20.  
  21. int x,n;
  22. cin>>x>>n;
  23.  
  24.     equation(x,n);
  25.  
  26.     return 0;
  27. }
  28.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement