fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. string id;
  6. long long int a, c, x, m,p,q,lastNonzero=0,n=10;
  7. cout<<"Enter your departmental ID: "<<endl;
  8. getline(cin,id);
  9.  
  10. for(int i = id.length()-1 ; i >=0; i--)
  11. {
  12. if(id[i]>'0' && id[i]<='9')
  13. {
  14. lastNonzero++;
  15. if(lastNonzero==1)
  16. {
  17. a = abs(id[i]-48);
  18. }
  19. else if(lastNonzero==2)
  20. {
  21. c = abs(id[i]-48);
  22. }
  23. else if(lastNonzero==3)
  24. {
  25. x = abs(id[i]-48);
  26. }
  27. else
  28. {
  29. break;
  30. }
  31. }
  32. }
  33. cout<<"Your Departmental ID : "<<id<<endl;
  34. cout<<"Here,"<<endl<<"last nonzero (a): "<<a<<endl<<"2nd last nonzero (c): "<<c<<endl<<"3rd last nonzero (x): "<<x<<endl;
  35. m = 18%c;
  36. if(m==0){
  37. m = 5;
  38. }
  39. q = c%m;
  40. cout<<"and the value of m: "<<m<<endl;
  41. cout<<endl<<"\t\tApplying Linear Congruential Method (x = a*x+c%m) for 10 times"<<endl<<endl;
  42. for(int i = 1 ; i <= n ; i++){
  43. p = a*x;
  44. x = p+q ;
  45. cout<<"for x"<<i<<" = "<<x<<" (Where a*x: "<<p<<" and c mod m: "<<q<<")"<<endl;
  46. }
  47. }
  48.  
Success #stdin #stdout 0s 5328KB
stdin
CSE 01806649
stdout
Enter your departmental ID: 
Your Departmental ID : CSE 01806649
Here,
last nonzero (a): 9
2nd last nonzero (c): 4
3rd last nonzero (x): 6
and the value of m: 2

		Applying Linear Congruential Method (x = a*x+c%m) for 10 times

for x1 = 54 (Where a*x: 54 and c mod m: 0)
for x2 = 486 (Where a*x: 486 and c mod m: 0)
for x3 = 4374 (Where a*x: 4374 and c mod m: 0)
for x4 = 39366 (Where a*x: 39366 and c mod m: 0)
for x5 = 354294 (Where a*x: 354294 and c mod m: 0)
for x6 = 3188646 (Where a*x: 3188646 and c mod m: 0)
for x7 = 28697814 (Where a*x: 28697814 and c mod m: 0)
for x8 = 258280326 (Where a*x: 258280326 and c mod m: 0)
for x9 = 2324522934 (Where a*x: 2324522934 and c mod m: 0)
for x10 = 20920706406 (Where a*x: 20920706406 and c mod m: 0)