All pastes #968946 Raw Edit

Miscellany

public c v1 · immutable
·published 2008-04-03 12:32 UTC
rendered paste body
#include <stdio.h>#include <stdlib.h>#include <math.h>using namespace std;long bigmod(long b,long p,long m) {  if (p == 0)    return 1;  else if (p%2 == 0)    return (long)pow(bigmod(b,p/2,m),2) % m; // square(x) = x * x  else    return (long)((b % m) * bigmod(b,p-1,m)) % m;}int main(){       	FILE *arq;	unsigned long b,m,p;	int a,b,c;		arq = fopen("dados.txt","rt");	while(!feof(arq)){        	scanf("%d",&b);	/*if(b==NULL)	   break;*/	scanf("%d",&p);	scanf("%d",&m);	printf("\n%d",bigmod(b,p,m));	}}