題意:首先輸入c n,接著是n個數,問你有沒有k個數(1<=k<=n),使得其和能整除c
輸出其對應下標,只輸出一組符合條件的就行;
代碼:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define N 100010
#define LL long long
#define mem(a) memset(a,0,sizeof(a));
#define mem_1(a) memset(a,-1,sizeof(a));
using namespace std;
int n,c;
int f[N];
int sum[N];
int pos[N];
void work()
{
int j;
memset(pos, -1, sizeof(pos));
pos[0] = 0;
for (int i = 1; i <= n; i++)
if (pos[sum[i]] == -1)
pos[sum[i]] = i;
else
{
for ( j = pos[sum[i]] + 1; j < i; j++)
printf(%d , j);
printf(%d , j);
return;
}
}
int main()
{
while(scanf(%d%d, &c,&n)){
if(c==0&&n==0)
break;
for (int i = 1; i <= n; i++)
scanf(%d, &f[i]);
sum[0] = f[0] = 0;
for (int i = 1; i <= n; i++)
sum[i] = (sum[i - 1] + f[i]) % c;
work();
}
return 0;
}