Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("cifra.in");
- ofstream g("cifra.out");
- int i,j,n,m;
- #define ll long long
- ll suma;
- ll rez2(ll x){
- ll y, h;
- //ll rez;
- y = x;
- x %= 10;
- if(x == 0) return 0;
- if(x == 1) return 1;
- if(x == 2){
- h = y % 4;
- if(h == 1) return 2;
- if(h == 2) return 4;
- if(h == 3) return 8;
- if(h == 0) return 6;
- }
- if(x == 3){
- h = y % 4;
- if(h == 1) return 3;
- if(h == 2) return 9;
- if(h == 3) return 7;
- if(h == 0) return 1;
- }
- if(x == 4){
- h = y % 2;
- if(h == 1) return 4;
- if(h == 0) return 6;
- }
- if(x == 5) return 5;
- if(x == 6) return 6;
- if(x == 7){
- h = y % 4;
- if(h == 1) return 7;
- if(h == 2) return 9;
- if(h == 3) return 3;
- if(h == 4) return 1;
- }
- if(x == 8){
- h = y % 4;
- if(h == 1) return 8;
- if(h == 2) return 4;
- if(h == 3) return 2;
- if(h == 0) return 6;
- }
- if(x == 9){
- h = y % 2;
- if(h == 1) return 9;
- if(h == 2) return 1;
- }
- return -1;
- }
- int main()
- {
- j = 0;
- cin >> m;
- while(j < m){
- cin >> n;
- j++;
- suma = 0;
- for(int i = 1; i <= n; ++i)
- suma += rez2(i) % 10;
- cout << suma % 10 << "\n";
- }
- f.close();
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement