torgiren

jelon

Oct 27th, 2020
762
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. int main()
  3. {
  4.     int P, P0, P1, P2, Q, N;
  5.     std::cout<<"Provide P0: ";
  6.     std::cin>>P0;
  7.     std::cout<<"Provide P1: ";
  8.     std::cin>>P1;
  9.     std::cout<<"Provide Q: ";
  10.     std::cin>>Q;
  11.     std::cout<<"Provide N: ";
  12.     std::cin>>N;
  13.  
  14.     P = P0;
  15.     if(N>1)
  16.     {
  17.         P*=10; P+=P1;
  18.     }
  19.     else
  20.         P=P0;
  21.     for(int i=2; i<N; i++)
  22.     {
  23.         P2 = (4 * P1 + P0) % Q;
  24.  
  25.         P*=10;
  26.         P+=P2;
  27.  
  28.         P0 = P1;
  29.         P1 = P2;
  30.  
  31.         std::cout<<i<<": "<<P<<std::endl;
  32.  
  33.     }
  34.     std::cout<<P<<" "<<Q<<" "<<P%Q<<std::endl;
  35.     std::cout<<(P%Q ? "NO" : "YES")<<std::endl;
  36. }
  37.  
RAW Paste Data