DANCING with the Stars” hopeful DANICA McKELLAR may be a math whiz – but she wasn’t counting on a

 broken rib!

The 39-year-old former “Wonder Years” star – who’s been wowing both judges and viewers with her fancy footwork on Season 18 of “DWTS” – suffered the painful injury during a grueling rehearsal session with her pro partner, Val Chmerkovskiy.

Danica tweeted on April 25: “So…I broke a rib in yesterday’s DWTS rehearsal. Trying my best to pull thru and could use your prayers!”

The actress, best-known for her portrayal as “Winnie” on “The Wonder Years,” was a top contender on “DWTS” right up until her accident. She and Val dazzled the judges with their performances, scoring a near-perfect 39 with a steaming cha cha just a week before her injury.

BUT Danica’s busted rib forced her to miss three days of rehearsals, and the injury throws the competition wide open.

“Had rehearsal today,” Danica later posted on

 Twitter. “It’s tough dancing with a broken rib.” She noted that Val “choreographed an amazing routine – fingers crossed I can pull it off.”

Brainy Danica studied mathematics at UCLA and is the author of a series of books which are designed to encourage young girls to tackle and succeed at the subject. She’s also mom to a 3-year-old son, Draco, with her ex-husband, composer Mike Verta.

Ironically, it seems as if Val may have known Danica was at risk for injury. A few days before she broke the rib, he said: “She’s very small and tender…She’s a strong woman but like, when I dance, I’m very physical. I can’t really control it because if I start to control it, then I’m not giving 100 percent of how I feel in the moment.

“And so, that combination is very brutal sometimes.”