It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days?
Input
There are multiple test cases. The first line 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
212
Sample Output
SundayThursday
Hint
A week consists of Sunday, Monday, Tuesday, Wednesday, Thursday, Friday and Saturday.
通过打表发现周期是294,那么就简单了
#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;char day[10][10] = {"Saturday","Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};int s[300];int work(int n){ int sum = 1,i; for(i = 1;i<=n;i++) { sum = sum*n; sum%=7; } return sum;}int main(){ int t,n,i,j,len; s[0] = 0; for(i = 1;i<=294;i++) { s[i] = s[i-1]+work(i); s[i]%=7; } scanf("%d",&t); while(t--) { scanf("%d",&n); n%=294; printf("%s\n",day[s[n]]); } return 0;}
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow