Advertisement
brospresident

[C++]infoarena_olimpiada_neoptimizat

Jan 13th, 2019
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. #include    <iostream>
  2. #include    <fstream>
  3.  
  4. using namespace std;
  5.  
  6. ifstream    f("cifra.in");
  7. ofstream    g("cifra.out");
  8.  
  9. int i,j,n,m;
  10.  
  11. #define     ll  long long
  12.  
  13. ll suma;
  14.  
  15. ll rez2(ll x){
  16.     ll y, h;
  17.     //ll rez;
  18.     y = x;
  19.     x %= 10;
  20.     if(x == 0) return 0;
  21.     if(x == 1) return 1;
  22.     if(x == 2){
  23.         h = y % 4;
  24.         if(h == 1) return 2;
  25.         if(h == 2) return 4;
  26.         if(h == 3) return 8;
  27.         if(h == 0) return 6;
  28.     }
  29.     if(x == 3){
  30.         h = y % 4;
  31.         if(h == 1) return 3;
  32.         if(h == 2) return 9;
  33.         if(h == 3) return 7;
  34.         if(h == 0) return 1;
  35.  
  36.     }
  37.     if(x == 4){
  38.         h = y % 2;
  39.         if(h == 1) return 4;
  40.         if(h == 0) return 6;
  41.     }
  42.     if(x == 5) return 5;
  43.     if(x == 6) return 6;
  44.     if(x == 7){
  45.         h = y % 4;
  46.         if(h == 1) return 7;
  47.         if(h == 2) return 9;
  48.         if(h == 3) return 3;
  49.         if(h == 4) return 1;
  50.     }
  51.     if(x == 8){
  52.         h = y % 4;
  53.         if(h == 1) return 8;
  54.         if(h == 2) return 4;
  55.         if(h == 3) return 2;
  56.         if(h == 0) return 6;
  57.     }
  58.     if(x == 9){
  59.         h = y % 2;
  60.         if(h == 1) return 9;
  61.         if(h == 2) return 1;
  62.     }
  63.     return -1;
  64. }
  65.  
  66. int main()
  67. {
  68.     j = 0;
  69.     cin >> m;
  70.     while(j < m){
  71.         cin >> n;
  72.         j++;
  73.         suma = 0;
  74.         for(int i = 1; i <= n; ++i)
  75.             suma += rez2(i) % 10;
  76.         cout << suma % 10 << "\n";
  77.     }
  78.     f.close();
  79.     g.close();
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement