1234567891011121314
#include <iostream> #include <cmath> using namespace std; int main() { int i; long long sum; for(i=1;i<=20;i++) sum = sum + pow(i,i+1); cout << sum; }
bar * (foo % k) == (bar * foo) % k
123456789101112131415161718
#include <iostream> using namespace std; int main () { // calculate last digit of x^y int x=3; int y=10; int pow=1; for(int i=1; i<=y; i++) { pow *= x; pow %= 10; // we need last digit only } cout << pow << endl; return 0; }