Advertisement
erfanul007

UVa 10680

Dec 30th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. // #pragma GCC optimize("Ofast,no-stack-protector")
  5. // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  6. // #pragma GCC optimize("unroll-loops")
  7.  
  8. typedef unsigned long long ull;
  9. typedef long long ll;
  10. typedef long double lld;
  11. typedef vector<int> vi;
  12. typedef vector<ll> vll;
  13. typedef vector<vi> vvi;
  14. typedef pair<int,int > pii;
  15. typedef pair<ll,ll > pll;
  16. typedef vector< pii > vpii;
  17. typedef vector< pll > vpll;
  18. typedef set<int> sti;
  19.  
  20. #define sc scanf
  21. #define pf printf
  22. #define sci(n) scanf("%d",&n)
  23. #define scii(n,m) scanf("%d %d",&n,&m)
  24. #define scl(n) scanf("%lld",&n)
  25. #define scd(n) scanf("%lf",&n)
  26. #define scs(s) scanf("%s",s)
  27. #define pfi(n) printf("%d",n)
  28. #define pfl(n) printf("%lld",n)
  29. #define pff(n) cout<<n
  30. #define spc printf(" ")
  31. #define line printf("\n")
  32. #define loop(i,x,y) for(int i=int(x); i<=int(y); i++)
  33. #define rloop(i,y,x) for(int i=int(y); i>=int(x); i--)
  34. #define cspf(i) printf("Case %d: ", i)
  35. #define vout(v) for(int w=0;w<v.size();w++){if(w) cout<<' '; cout<<v[w];}
  36. #define clr(a,x) memset(a,x,sizeof(a))
  37. #define tp(v,j) get<j>(v)
  38. #define pb push_back
  39. #define mp make_pair
  40. #define mt make_tuple
  41. #define ff first
  42. #define ss second
  43. #define all(v) v.begin(),v.end()
  44. #define rall(v) v.rbegin(),v.rend()
  45. #define read() freopen("input.txt", "r", stdin)
  46. #define write() freopen("output.txt", "w", stdout)
  47. #define fastIO() ios_base::sync_with_stdio(false); cin.tie(NULL);
  48. /// Constants
  49. #define eps 1e-6
  50. #define PI acos(-1.0) // 3.1415926535897932
  51. #define MAX (ll)2147483647
  52. #define MAXn 1000009
  53.  
  54. int GCD(int a, int b) { return b == 0 ? a : GCD(b , a % b); }
  55. ll LCM(ll a, ll b) { return a * (b/GCD(a, b)); }
  56.  
  57. vi prime;
  58. bool chk[MAXn];
  59.  
  60. void seive()
  61. {
  62. clr(chk,true);
  63. chk[0]=chk[1]=false;
  64. for(int i=4;i<MAXn;i+=2) chk[i]=false;
  65. for(int i=3;i<=MAXn/i;i+=2){
  66. if(!chk[i]) continue;
  67. for(int j=i*i;j<MAXn;j+=(2*i)) chk[j]=false;
  68. }
  69. prime.pb(3);
  70. for(int i=7;i<MAXn;i+=2){
  71. if(chk[i]) prime.pb(i);
  72. }
  73. }
  74.  
  75.  
  76. int main()
  77. {
  78. #ifdef VAMP
  79. clock_t tStart = clock();
  80. freopen("input.txt", "r", stdin);
  81. freopen("output.txt", "w", stdout);
  82. #endif
  83.  
  84. seive();
  85.  
  86. while(1){
  87. int n;
  88. sci(n);
  89. if(!n) break;
  90. int ans=1;
  91. int cnt2=0,cnt5=0;
  92.  
  93. for(int i=2;i<=n;i*=2) cnt2++;
  94. for(int i=5;i<=n;i*=5) cnt5++;
  95.  
  96. for(int i=0;i<cnt2-cnt5;i++) ans = ((ans%10)*(2%10))%10;
  97.  
  98. for(int i=0;prime[i]<=n;i++){
  99. for(int j=n;j>=prime[i];j/=prime[i]){
  100. ans = ((ans%10)*(prime[i]%10))%10;
  101. }
  102. }
  103. pfi(ans);line;
  104. }
  105.  
  106.  
  107. #ifdef VAMP
  108. fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
  109. #endif
  110.  
  111. return 0;
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement