Pagini recente » Cod sursa (job #1691526) | Cod sursa (job #1948191) | Cod sursa (job #1602217) | Cod sursa (job #2949509) | Cod sursa (job #2122348)
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
typedef unsigned int uint;
#define M 9901
void fact(uint64_t a, uint64_t b, FILE *out);
uint64_t binexp(uint64_t x, uint64_t n);
uint64_t egcd(uint64_t a, uint64_t b, uint64_t *x, uint64_t *y);
uint64_t inv(uint64_t a, uint64_t m);
int main(void)
{
FILE *in = fopen("sumdiv.in", "r");
FILE *out = fopen("sumdiv.out", "w");
if(in != NULL && out != NULL)
{
uint64_t a, b;
fscanf(in, "%llu%*c%llu", &a, &b);
fact(a, b, out);
fclose(in);
fclose(out);
}
else
{
printf("file error\n");
}
return 0;
}
uint64_t inv(uint64_t a, uint64_t m)
{
uint64_t x, y;
uint64_t d = egcd(a, m, &x, &y);
if(d == 1)
{
return ((x % m) + m) % m;
}
else
{
printf("No invers moduloar\n");
}
}
uint64_t egcd(uint64_t a, uint64_t b, uint64_t *x, uint64_t *y)
{
if(a == 0)
{
*x = 0;
*y = 1;
return b;
}
else
{
uint64_t x1, y1;
uint64_t d = egcd(b % a, a, &x1, &y1);
*x = y1 - (b / a) * x1;
*y = x1;
return d;
}
}
uint64_t binexp(uint64_t x, uint64_t n)
{
uint64_t res = 1;
while(n)
{
if(n % 2 != 0)
{
res = ((res % M) * (x % M)) % M;
}
x = ((x % M) * (x % M)) % M;
n /= 2;
}
return res;
}
void fact(uint64_t a, uint64_t b, FILE *out)
{
uint64_t s = 1;
uint64_t d = 2;
while(a > 1)
{
uint64_t p = 0;
while(a % d == 0)
{
p++;
a /= d;
}
if(p)
{
p += b;
uint64_t calc = (((binexp(d, p) - 1) % M) * (inv(d - 1, p))) % M;
s = ((s % M) * (calc % M)) % M;
}
d++;
if(a > 1 && d * d > a)
{
d = a;
}
}
fprintf(out, "%llu\n", s);
}