1082 and 7 unrelated numbers
Base time limit: 1 seconds Space limit: 131072 kb A positive integer, if it can be divisible by 7, or its decimal notation in a single digit number is 7, it is said to be the number associated with 7. The sum of the squares of all positive integers that are less than or equal to N and 7 independent. For example: N = 8,<= 8 and 7 are unrelated to the number including: 1 2 3 4 5 6 8, squared sum is: 155. Input
Line 1th: A number t that represents the number of numbers that are later used as input tests. (1 <= T <= 1000) 2-t + 1 lines: 1 number n per line. (1 <= N <= 10^6)
Output
A total of T-lines, one number per line, corresponding to the results of the T test.
Input example
545678
Output example
30559191155
//play the table;#include <cstdio>#defineN 1000000typedefLong LongLL; LL Sb[n+10000];voidsieve () { for(intI=1; i<=n+ -; i++) { if(i%7!=0) { intq=i; BOOLflag=0; while(Q) {intR= q%Ten; if(r==7) {flag=1; Break; } Q/=Ten; } if(flag==1) Sb[i]=sb[i-1]; if(flag==0) Sb[i]=sb[i-1]+ (LL) i*i; } ElseSb[i]= sb[i-1]; }}intMain () {sieve (); intT; scanf ("%d", &t); while(t--) { intN; scanf ("%d", &N); printf ("%lld\n", Sb[n]); } return 0;}
1082 and 7 unrelated numbers