It sounds to me like there are two approaches here.
- Ask them courteously to move along so that you can do your own work. "Hey, can we discuss this later? I need to get back to work." "Sorry, I can't really talk right now - I'd like to get this done today." If it continues, you may need to be a little more direct. "Please don't visit me while I'm working - it is distracting. I can speak to you during lunch/break if you want." Of course, this assumes you actually want to talk to them at all...
- Address them privately as a friend (or a concerned co-worker). This one's a little trickier because you don't want to overstep your bounds or misspeak for the company/manager. But something brief which shows your concern for the person. "Hey, I think you should spend more time during the day doing your work. I'd hate to see you get in trouble or even get fired for it." You definitely don't need to push the envelope or get into an argument.
Number 2 is definitely not necessary - it's more of a courtesy. It could also make you very unpopular with the person, so you'll have to gauge if you have enough of a relationship with them to do it at all.
Your manager is another factor - it's unclear from the question what their role is in this whole thing, but they definitely play an important one. It's ultimately their job to discipline employees who are not working. It's your job to get your job done.