Vladislav_Bezruk

Some task

Nov 14th, 2020 (edited)
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.32 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. long long s,n,k;
  4.  
  5. int main() {
  6.    
  7.     scanf("%lli %lli",&n,&k);
  8.     s = 1;
  9.    
  10.     while (n>0) {
  11.        
  12.     if (s > 1e18/n) {
  13.        
  14.     s = -1;
  15.     break; 
  16.        
  17.     }  
  18.            
  19.     s = s*n;   
  20.     n = n - k; 
  21.        
  22.     }
  23.  
  24.     if (s>0)
  25.     printf("%lli\n",s);
  26.     else
  27.     printf("overflow");
  28.            
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment