MOSCOW, MAY 25 -- Shoppers throughout the Soviet Union have gone on a binge of panic buying following this week's government announcement that food prices will double and triple over the coming months.

In an attempt to cut down on the wave of hoarding and prevent deeper food shortages, Moscow city authorities announced plans today to restrict the sale of many foods and consumer products to registered city residents for at least the next two weeks.

Prime Minister Nikolai Ryzhkov said he may resign if he is unable to win support for the government's new program to gradually change the economy from a system of central planning to a "socialist market."

"I do not work only to cling to my position," Ryzhkov told reporters. "If there is no confidence in the government, then a new government will have to begin work."

Signs of anxiety, resistance and panic were evident throughout the country over the new program, which calls for the tripling of bread prices July 1 and widespread increases in meat, milk and other food prices in coming months. Radio Moscow said that sales of oats, flour, butter and many other goods "rose by a factor of six to eight times" after Ryzhkov's nationally televised speech Thursday.

At grocery stores throughout the city, many shoppers tried to stock up on food products before the prices go up. In Leningrad, spaghetti, flour and cereals have been swept off the shelves by desperate shoppers, according to local journalists.

Ukrainian Premier Vitali Masol told the republic's legislature in Kiev that the Ukrainian government would stand in "firm opposition" to the new economic package. His speech was greeted by a burst of applause, according to a Ukrainian news agency.

Miners in the Ukrainian city of Donetsk said they would stage demonstrations to protest the price increases and might organize a nationwide miners' strike in early June. "If these {economic} plans come true, we could only die from hunger," said Vladimir Minenko of the Donetsk strike committee.

In the Ukraine, the second most populous Soviet republic, Masol said panic buying was widespread, with sales of flour going from 80 tons a day to 500 tons on Thursday. Sales of spaghetti and cooking oil also skyrocketed, Masol said.

On every park bench, in every line in Moscow, the talk was of the coming wave of inflation. While price increases are both painful and easy to comprehend, most people here have only the vaguest notion of what the government means when it speaks of a "market economy."

When the government unveiled its proposals earlier in the week, Deputy Prime Minister Leonid Abalkin said he realized the economy would get worse before it got better. Officials said they expect the next two or three years to be especially difficult for consumers.

Ryzhkov, speaking at a news conference, said the government anticipated widespread hoarding as a reaction to the announcement of price rises, but added, "I am appealing for restraint and calm." He said that the price of bread, which has been heavily subsidized for decades, had to rise in order to cut down on foreign grain imports. Ryzhkov said the Soviet Union is importing large amounts of grain. "There is no money to pay for all this," he said.

In the national legislature, some of the criticism was fierce. Gennadi Fishlin of the radical Inter-Regional Group of deputies said the new plan shows no vision of a market "except that it doubles prices."

Radio Moscow estimated that about 200 of the 542 deputies could vote in favor of a motion of no-confidence. Under a new law, a vote of two-thirds is necessary to bring down the government.

Ryzhkov said the government's program will undergo "nationwide public discussion" and may be put to a referendum.

But at a news conference today, President Mikhail Gorbachev appeared to backtrack from an earlier statement by Deputy Prime Minister Yuri Maslyukov pledging a nationwide referendum on the economic program. Noting that a referendum law had not yet been adopted by the Supreme Soviet, or standing legislature, Gorbachev said there was a "pluralism of opinions" among his advisers and refrained from endorsing the referendum idea himself.

As the economy grows worse, Gorbachev's government has become less popular. To carry out radical economic changes, it feels it must have a degree of political legitimacy before asking the population to make prolonged sacrifices.

One of the main intentions of the new program is to reduce or eliminate the authority of Moscow's planning agencies, which have traditionally dictated levels of production to enterprises throughout the country. Maslyukov, who heads the central planning organ Gosplan, said the program would eventually eliminate the need for Gosplan. It would be replaced by an economics ministry based on a West German model, he said.