Pagini recente » Cod sursa (job #509216) | Cod sursa (job #1163514) | Cod sursa (job #1567127) | Cod sursa (job #612437) | Cod sursa (job #28966)
Cod sursa(job #28966)
/***************************************************************************
* Copyright (C) 2007 by Nistor Andrei *
* [email protected] *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <fstream>
using namespace std;
int ultima(long long x){
long long y=x%10;
switch (y){
case 1: return 1;
case 2: if ((x/10)%2) return 6;
else return 4;
case 3: if ((x/10)%2) return 3;
else return 7;
case 4: return 6;
case 5: return 5;
case 6: return 6;
case 7: if ((x/10)%2) return 7;
else return 3;
case 8: if ((x/12)%2) return 4;
else return 6;
case 9: return 9;
case 0: return 0;
}
}
int main(int argc, char *argv[])
{
long long N, j;
int T, i, z, S;
fstream in("cifra.in", ios::in);
fstream out("cifra.out", ios::out);
in>>T;
for (i=1; i<=T; ++i){
S=0;
in>>N;
S+=7*(N/10);
for( j=(N/10)*10 ; j<=N ; ++j ){
S+=ultima(j);
}
out<<S%10<<"\n";
}
in.close();
out.close();
return 0;
}