mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
commit
ec1dee204d
44
CWOJ/1193-more_冰封.cpp
Normal file
44
CWOJ/1193-more_冰封.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#define LL long long
|
||||||
|
|
||||||
|
LL fast_plus(LL a, LL b, LL m) {
|
||||||
|
LL ret = 0;
|
||||||
|
while(b) {
|
||||||
|
if(b & 1)
|
||||||
|
ret = (ret + a) % m;
|
||||||
|
b >>= 1;
|
||||||
|
a = (a << 1) % m;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
LL fast_pow(LL a, LL b, LL m) {
|
||||||
|
LL ret = 1;
|
||||||
|
while(b) {
|
||||||
|
if(b & 1)
|
||||||
|
ret = fast_plus(ret, a, m);
|
||||||
|
b >>= 1;
|
||||||
|
a = fast_plus(a, a, m);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int i;
|
||||||
|
LL n, m, t, aa = 0;
|
||||||
|
char a[10005];
|
||||||
|
ifstream fin;
|
||||||
|
fin.open("password.in");
|
||||||
|
std::cin.sync_with_stdio(false);
|
||||||
|
std::cin>>a>>n>>m;
|
||||||
|
for(i = 0; i < strlen(a); i++)
|
||||||
|
aa = (aa * 10 + a[i] - '0') % m;
|
||||||
|
if(n == 1)
|
||||||
|
std::cout<<aa<<' '<<fast_plus(aa, aa, m);
|
||||||
|
t = fast_pow(aa, n, m);
|
||||||
|
std::cout<<t<<' '<<fast_plus(t, aa, m);
|
||||||
|
return 0;
|
||||||
|
}
|
36
CWOJ/1193-wrong_冰封.cpp
Normal file
36
CWOJ/1193-wrong_冰封.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <math.h>
|
||||||
|
#define LL long long
|
||||||
|
|
||||||
|
LL fast_plus(LL a, LL b, LL m) {
|
||||||
|
LL ret = 0;
|
||||||
|
while(b) {
|
||||||
|
if(b & 1)
|
||||||
|
ret = (ret + a) % m;
|
||||||
|
b >>= 1;
|
||||||
|
a = (a << 1) % m;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
LL fast_pow(LL a, LL b, LL m) {
|
||||||
|
LL ret = 1;
|
||||||
|
while(b) {
|
||||||
|
if(b & 1)
|
||||||
|
ret = (ret * a) % m;
|
||||||
|
b >>= 1;
|
||||||
|
a = fast_plus(a, a, m);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
LL n, m, t, a;
|
||||||
|
std::cin.sync_with_stdio(false);
|
||||||
|
std::cin>>a>>n>>m;
|
||||||
|
t = fast_pow(a, n, m);
|
||||||
|
std::cout<<t<<' '<<fast_plus(t, a, m)<<'\n';
|
||||||
|
return 0;
|
||||||
|
}
|
2
CWOJ/Readme.md
Normal file
2
CWOJ/Readme.md
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#成都外国语学校 CWOJ
|
||||||
|
[Goto Home Page](https://www.cwoj.tk/ "Welcome to CWOJ")
|
13
POJ/1000_冰封.java
Normal file
13
POJ/1000_冰封.java
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ice1000
|
||||||
|
* Created by weber on 2016/6/13.
|
||||||
|
*/
|
||||||
|
public class Main {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
int a = scanner.nextInt(), b = scanner.nextInt();
|
||||||
|
System.out.println(a + b);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user