/*MAIN函数*/
# include <iostream.h>
# include <string.h>
# include <fstream.h>
# include <math.h>
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
# define ul unsigned long
ul isPrime(ul n)
{
ul b=1;
for(ul i=2;i<n;i++)
if(n%i==0) { b=0; break; }
return b;
}
ul Power(ul x,ul y)
{
ul ans=1;
if(x==1) return x;
for(ul i=1;i<=y;i++)
ans*=x;
return(ans);
}
char * ToBin(int x)
{
char *ans=new char[20];
int i=0;
while(x>=1)
{
if(x%2==1) ans[i]='1'; else ans[i]='0';
x/=2; i++;
}
if(x==1) ans[i]='1',i++;
ans[i]='\0';
strrev(ans);
return(ans);
}
ul Crypt(int x,int key,int n) // (x^y)%z //Method 2
{
char *B=new char[20];
B=ToBin(key);
ul ans=1;int c=1;
for(int i=0;i <strlen(B);i++)
{
c=2*c;
ans=(ans*ans)%n;
if(B[i]=='1')
{
c=c+1;
ans=(ans*x)%n;
}
}
return(ans);
}
void Fun1(int,int,int);
int Bin2Num(char *s)
{
int ans=0; int i,j;
for(j=0,i=7;i>=0;j++,i--)
- 1
- 2
前往页