David Cameron was subjected to a bizarre quiz on British culture and history as he appeared on one of the USA's most influential TV chat shows last night.

The Prime Minister was welcomed on to the Late Show by host David Letterman to the tune of the house band playing Rule Britannia and dry ice pumping into the studio to replicate a London fog.

And after a brief foray into the issues surrounding Syria and the Arab Spring - the subject of his speech to the United Nations earlier in the day - Letterman confronted him with a truly tough question - who composed Rule Britannia?

A floundering Mr Cameron made a guess at Edward Elgar, only to learn from Letterman's researchers that it was in fact the little-known Thomas Arne, setting words by James Thomson to music.

He also admitted to being stumped when asked for the English translation of Magna Carta - Great Charter - and hesitated a while before naming Runnymede as the location of its signing.

But he immediately named 1215 as the date it was drawn up and was able to give an account of its importance in the birth of democracy.

Mr Cameron is the first sitting British prime minister to join Letterman in the Ed Sullivan Theatre on Broadway - venue for the Beatles' first US TV performance in 1964 - though Tony Blair has appeared twice on the show since leaving office.

Much of Letterman's questioning appeared designed as an idiot's guide to Britain for American viewers, as he asked Mr Cameron to name the four nations of the UK. "What is the deal on Wales?" asked Letterman. "Did they vote for you, the people of Wales?" "Some of them did," replied Mr Cameron - and explained the difference between Northern Ireland and the Republic.

Mr Cameron had said he would use the show to "bang the drum" for Britain, and raised applause from the audience when he hailed the successful hosting of the Olympics and Paralympics this summer.

But he, perhaps diplomatically, ignored an apparent dig by Letterman at Republican presidential candidate Mitt Romney, who famously questioned if London was ready for the Olympics.

"The idea that two major world class athletics events took place in London... who would have bet against that going off flawlessly, as it seems to have done?" joked Letterman.

Mr Cameron also boasted of his government's efforts to create a good environment for investment in the UK and about the creation of one million private sector jobs over the past two years.

But he admitted that he was "not very popular at the moment" - blaming his low ratings on the austerity policies needed to cut the deficit.

Mr Cameron had to correct Letterman when he talked about "the British empire" - "it's not an empire, it's the United Kingdom", interrupted the PM - and when the host suggested Northern Ireland was "part of England.

The PM raised a laugh from the studio audience for the CBS show as he joked about Britain's historic relations with the US.

"There were some good bits and some less than good bits, and obviously we had a bit of a falling out," he said.

"I like to think we've got over that now."

In an indication of his determination to forge good relations with the victor of the upcoming presidential elections, he said: "I have got on well with Republicans, I can get on well with Democrats."

The loudest applause of the evening came when he revealed that Britain does not allow political advertising on TV - a major issue in the US as both Mr Romney and Barack Obama have spent lavishly on attack ads in a multi-billion dollar presidential campaign.

But he revealed that it was thanks to TV that he was first recognised in the USA, when he was walking in the streets of New York and spotted by a passer-by who shouted: "Hey! Prime Minister's Questions! We love your show!"

It is understood that the PM's team approached the Late Show to let them know Mr Cameron would be available during his visit to New York for the United Nations General Assembly.

They were aware that they could be taking a risk in putting the Prime Minister up against the irreverent Letterman, who is known for off-the-wall questions - asking recent guest Boris Johnson if he cut his own hair.

The long-running Late Show has a daily audience of around three million with a mix of showbiz stars, humour and hard-hitting political interviews which regularly set the news agenda. Last week President Barack Obama used the show to issue his response to election rival Mitt Romney's claim that 47% of US voters saw themselves as victims.

Also on tonight's British-themed edition were Trainspotting actor Jonny Lee Miller - now starring in CBS series Elementary, a US version of Sherlock Holmes - and folk-rock band Mumford & Sons.

Explaining the decision for the PM to appear with Letterman, one British government source said: "It is just a good opportunity. Britain has had an extraordinary year with the Jubilee, with the Olympics and with the Paralympics. We have got something good to shout about.

"So getting out there talking up Britain is important. We should never forget that we are the biggest investor in America, America is the biggest investor in us.

"There is a saying in business that when you want to do better you go back to your biggest customers and try and squeeze out a bit more."