Go: package main

import (
        "fmt"
)

func main() {
        var weeks = []string{"Thursday",
                "Friday",
                "Saturday",
                "Sunday",
                "Monday",
                "Tuesday",
                "Wednesday"}

        for {
                var m, d int
                _, err := fmt.Scanf("%d %d", &m, &d)
                if err != nil || m + d == 0 {
                        break
                }
                var days int

                for {
                        lm, ld := getLastDay(m, d)
                        if lm + ld == 0 {
                                break
                        }
                        days++
                        m = lm
                        d = ld
                }
                fmt.Println(weeks[days%7])
        }
}

func getLastDay(m int, d int) (lm int, ld int) {
        if m == 1 && d == 1 {
                return 0, 0
        }

        if d > 1 {
                return m, d-1
        } else {
                if m == 3 {
                        return m-1, 29
                }
                if m == 3 || m == 5 || m == 7 || m == 10 || m == 12 {
                        return m-1, 30
                } else {
                        return m-1, 31
                }
        }
}

C++: #include <iostream>
using namespace std;
int main(void){
    int a,b;
    while (cin >>a>>b) {
        if(a==0 && b==0) break;
        
        else if(a==1){
            if((b+7)%7==1) cout<<"Thursday"<<endl; else if((b+7)%7==2) cout<<"Friday"<<endl;
            else if((b+7)%7==3) cout<<"Saturday"<<endl; else if((b+7)%7==4) cout<<"Sunday"<<endl;
            else if((b+7)%7==5) cout<<"Monday"<<endl; else if((b+7)%7==6) cout<<"Tuesday"<<endl;
            else cout<<"Wednesday"<<endl;
        }
        
        else if(a==2){
            if((b+7)%7==1) cout<<"Sunday"<<endl; else if((b+7)%7==2) cout<<"Monday"<<endl;
            else if((b+7)%7==3) cout<<"Tuesday"<<endl; else if((b+7)%7==4) cout<<"Wednesday"<<endl;
            else if((b+7)%7==5) cout<<"Thursday"<<endl; else if((b+7)%7==6) cout<<"Friday"<<endl;
            else cout<<"Saturday"<<endl;
        }
        else if(a==3){
            if((b+7)%7==1) cout<<"Monday"<<endl; else if((b+7)%7==2) cout<<"Tuesday"<<endl;
            else if((b+7)%7==3) cout<<"Wednesday"<<endl; else if((b+7)%7==4) cout<<"Thursday"<<endl;
            else if((b+7)%7==5) cout<<"Friday"<<endl; else if((b+7)%7==6) cout<<"Saturday"<<endl;
            else cout<<"Sunday"<<endl;
        }
        
        else if(a==4){
            if((b+7)%7==1) cout<<"Thursday"<<endl; else if((b+7)%7==2) cout<<"Friday"<<endl;
            else if((b+7)%7==3) cout<<"Saturday"<<endl; else if((b+7)%7==4) cout<<"Sunday"<<endl;
            else if((b+7)%7==5) cout<<"Monday"<<endl; else if((b+7)%7==6) cout<<"Tuesday"<<endl;
            else cout<<"Wednesday"<<endl;
        }
        
        else if(a==5){
            if((b+7)%7==1) cout<<"Saturday"<<endl; else if((b+7)%7==2) cout<<"Sunday"<<endl;
            else if((b+7)%7==3) cout<<"Monday"<<endl; else if((b+7)%7==4) cout<<"Tuesday"<<endl;
            else if((b+7)%7==5) cout<<"Wednesday"<<endl; else if((b+7)%7==6) cout<<"Thursday"<<endl;
            else cout<<"Saturday"<<endl;
        }
        
        else if(a==6){
            if((b+7)%7==1) cout<<"Tuesday"<<endl; else if((b+7)%7==2) cout<<"Wednesday"<<endl;
            else if((b+7)%7==3) cout<<"Thursday"<<endl; else if((b+7)%7==4) cout<<"Friday"<<endl;
            else if((b+7)%7==5) cout<<"Saturday"<<endl; else if((b+7)%7==6) cout<<"Sunday"<<endl;
            else cout<<"Monday"<<endl;
        }
        
        
        else if(a==7){
            if((b+7)%7==1) cout<<"Thursday"<<endl; else if((b+7)%7==2) cout<<"Friday"<<endl;
            else if((b+7)%7==3) cout<<"Saturday"<<endl; else if((b+7)%7==4) cout<<"Sunday"<<endl;
            else if((b+7)%7==5) cout<<"Monday"<<endl; else if((b+7)%7==6) cout<<"Tuesday"<<endl;
            else cout<<"Wednesday"<<endl;
        }
        
        else if(a==8){
            if((b+7)%7==1) cout<<"Sunday"<<endl; else if((b+7)%7==2) cout<<"Monday"<<endl;
            else if((b+7)%7==3) cout<<"Tuesday"<<endl; else if((b+7)%7==4) cout<<"Wednesday"<<endl;
            else if((b+7)%7==5) cout<<"Thursday"<<endl; else if((b+7)%7==6) cout<<"Friday"<<endl;
            else cout<<"Saturday"<<endl;
            
        }
        
        else if(a==9){
            if((b+7)%7==1) cout<<"Wednesday"<<endl; else if((b+7)%7==2) cout<<"Thursday"<<endl;
            else if((b+7)%7==3) cout<<"Friday"<<endl; else if((b+7)%7==4) cout<<"Saturday"<<endl;
            else if((b+7)%7==5) cout<<"Sunday"<<endl; else if((b+7)%7==6) cout<<"Monday"<<endl;
            else cout<<"Tuesday"<<endl;
        }
        
        else if(a==10){
            if((b+7)%7==1) cout<<"Friday"<<endl; else if((b+7)%7==2) cout<<"Saturday"<<endl;
            else if((b+7)%7==3) cout<<"Sunday"<<endl; else if((b+7)%7==4) cout<<"Monday"<<endl;
            else if((b+7)%7==5) cout<<"Tuesday"<<endl; else if((b+7)%7==6) cout<<"Wednesday"<<endl;
            else cout<<"Thursday"<<endl;
            
        }
        
        else if(a==11){
            if((b+7)%7==1) cout<<"Monday"<<endl; else if((b+7)%7==2) cout<<"Tuesday"<<endl;
            else if((b+7)%7==3) cout<<"Wednesday"<<endl; else if((b+7)%7==4) cout<<"Thursday"<<endl;
            else if((b+7)%7==5) cout<<"Friday"<<endl; else if((b+7)%7==6) cout<<"Saturday"<<endl;
            else cout<<"Sunday"<<endl;
        }
        else if(a==12){
            if((b+7)%7==1) cout<<"Wednesday"<<endl; else if((b+7)%7==2) cout<<"Thursday"<<endl;
            else if((b+7)%7==3) cout<<"Friday"<<endl; else if((b+7)%7==4) cout<<"Saturday"<<endl;
            else if((b+7)%7==5) cout<<"Sunday"<<endl; else if((b+7)%7==6) cout<<"Monday"<<endl;
            else cout<<"Tuesday"<<endl;
        }
        
        
        
    }
}

C++: #include <iostream>
#include <string>
using namespace std;


int main() {
  const int n_day[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  const string week_name[] = {
    "Wednesday",
    "Thursday",
    "Firday",
    "Saturday",
    "Sunday",
    "Monday",
    "Tuesday"
  };


  int m, d, sum=0;
  cin >> m >> d;
  while(m != 0 && d != 0) {
    m--;
    for(int i=0; i<m; i++) {
      sum += n_day[i];
    }
    sum += d;
    cout << week_name[sum%7] << endl;
    sum = 0;
    cin >> m >> d;
  }
  return 0;
}

C++: 
import sys
import math

dayy = [0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

def days(a, day):
    if a == 0:
        return day
    else:
        return days(a-1, day + dayy[a])


while 1:
    inp = raw_input().split()
    ii = int(inp[0])
    jj = int(inp[1])
    if ii == 0 and jj== 0:
        break
    ans = days(ii-1, 0) + jj
    ans = ans % 7
    if ans == 1:
        print "Thursday"
        continue
    if ans == 2:
        print "Friday"
        continue
    if ans == 3:
        print "Saturday"
        continue
    if ans == 4:
        print "Sunday"
        continue
    if ans == 5:
        print "Monday"
        continue
    if ans == 6:
        print "Tuesday"
        continue
    if ans == 0:
        print "Wednesday"
        continue

C++: #include <iostream>
#include <cstdio>
using namespace std;
string name[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int dayOfWeek(int y, int m, int d) {
    if(m == 1 || m == 2) {
        y--;
        m += 12;
    }
    return(y + y / 4 - y / 100 + y / 400 + (13*m + 8) / 5 + d) % 7;
}

int main(void) {
    int y = 2004, m, d;
    while(scanf("%d %d", &m, &d), m + d != 0) {
        cout << name[dayOfWeek(y, m, d)] << endl;
    }
    return(0);
}