It ' s Saturday today, what the it after + + + ... + NN days? Input
There are multiple test cases. The "a" of input contains an integer T indicating the number of test cases. For each test case:
There is only one line containing one integer n (1 <= n <= 1000000000). Output
For each test case, output one string indicating the ' Day of week. Sample Input
2
1
2
Sample Output
Sunday
Thursday
Hint
A Week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
The general meaning of the topic is as follows:
is to give you one + + + + ... + nn this formula, and tell you now is Saturday, want you to judge in one + + + + ... + nn after so many days is the day of the week.
At first I thought that if I wrote directly, I would have timed out. Then that it must have a regular, then the first I was to calculate the value by hand, but after 7 to find that it is impossible to continue, and then I know that you can use the table to find the cycle of this method to find the law, so go to the system to learn a bit.
#include <stdio.h>
#include <string.h>
int main () {
char word[100];
scanf ("%s", word);
int Len=strlen (word);
I represents the cycle for
(int i=1;i<=len;i++) if (len%i==0) { //here because I'm asking for a string cycle, so if I can be divisible by Len, then it's a cycle, and then the following judgment ;
//ok used to mark;
int ok=1;
for (int j=i;j<len;j++)
//The following statement is the key. Determine if the first j is equal to the previous one;
if (word[j]!=word[j%i]) {ok=0; break;}}
}
So the above method can be used to find the problem of the cycle is 294, so good to do;
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
Char ss[8][10]={"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
int work (int n) {
int sum=1;
for (int i=1;i<=n;i++) {
sum=sum*n;
sum=sum%7;
}
return sum;
}
int main () {
int t,n;
int f[301]={0};
for (int i=1;i<=294;i++) {
f[i]=f[i-1]+work (i);
f[i]=f[i]%7;
}
scanf ("%d", &t);
while (t--) {
scanf ("%d", &n);
n=n%294;
printf ("%d\n", F[n]);
int t=f[n];
printf ("%s\n", Ss[t]);
}
Very useful way, haha.