#CS40108. 阅读程序-1模拟策略-8

阅读程序-1模拟策略-8

阅读程序

注意:切勿用电脑直接运行代码得出答案,请用大脑+笔+纸运行代码答题,否则是在浪费你的时间。

第一节:模拟策略

第8题【NOIP】2009

#include <iostream>
using namespace std;
const int c=2009;
int main()
{
	int n,p,s,i,j,t;
	cin >> n >> p;
	s=0;t=1;
	for(i=1;i<=n;i++)
	{
		t=t*p%c;
		for(j=1;j<=i;j++)
			s=(s+t)%c;
	}
	cout << s << endl;
	return 0;
}

●判断题

(1)将12 13行改为s=(s+111*t*i)%c;,程序输出不会改变。 ( )

{{ select(8-1) }}

(2)将15行改为printf(“%d\n”,s);程序输出不会改变。( )

{{ select(8-2) }}

(3)将08行的s=0;去掉,程序输出不会改变。( )

{{ select(8-3) }}

(4)将03行const去掉,程序输出不会发生变化。( )

{{ select(8-4) }}

●选择题

(5)输入为“11 2”,输出为( )。

{{ select(8-5) }}

  • 782
  • 762
  • 802
  • 114

(6)该算法的时间复杂度为( )。

{{ select(8-6) }}

  • O(1)
  • O(n)
  • O(n2n^2)
  • O(nlogn)