Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "euler.h"
- #include <gmp.h>
- #include <stdlib.h>
- #include "smmintrin.h"
- #include "emmintrin.h"
- #include <immintrin.h>
- void pb1(){
- int i, sum=0;
- for(i=0;i<1e3;i++){
- if (i%3==0 || i%5==0){
- sum+=i;
- }
- }
- printf("%d\n", sum);
- }
- void pb2(){
- mpz_t a, b,r,two;
- mpz_inits(a,b,r,two,NULL);
- mpz_set_ui(a,1);
- mpz_set_ui(b,0);
- mpz_set_ui(r,1);
- mpz_set_ui(two,2);
- int i=0;
- while (mpz_get_ui(a)< 4000000){
- mpz_fib_ui(a,i);
- mpz_mod(r,a,two);
- if( mpz_get_ui(r)==0){
- mpz_add_ui(b,b,mpz_get_ui(a));
- }
- i++;
- }
- printf("%s \n", mpz_get_str(NULL,10,b));
- mpz_clears(a,r,b,two,NULL);
- }
- void pb4(){
- unsigned long long n=21,flag = 0;
- while(flag==0){
- if (isDivisible(n)==1){
- flag = 1;
- printf("%lld\n", n);
- }
- n+=2;
- }
- }
- void pb9(){
- int a,b,c;
- for(a=1;a<1000;a++){
- for(b=1;b<1000;b++){
- for(c=1;c<1000;c++){
- if (a+b+c==1000 && a*a+b*b==c*c){
- printf("%d\n", a*b*c);
- return;
- }
- }
- }
- }
- }
- void pb14(){
- unsigned n,i,cnt,res = 0, max_cnt=0;
- for (i=1;i<1e6;i++){
- n=i;
- cnt=0;
- while(n!=1){
- n=(n&1)?3*n+1 :n/2;
- cnt++;
- }
- if (cnt > max_cnt){
- max_cnt = cnt;
- res = i;
- }
- }
- printf("%d\n", res);
- }
- void pb16(){
- unsigned long i=0;
- mpz_t n, tmp;
- mpz_inits(n,tmp,NULL);
- mpz_set_ui(tmp,0);
- mpz_set_ui(n,0);
- mpz_ui_pow_ui(n,2,1000);
- while(mpz_sgn(n)){
- i+= mpz_mod_ui(tmp,n,10);
- mpz_fdiv_q_ui(n,n,10);
- }
- printf("%ld\n", i);
- printf("%s\n", mpz_get_str(NULL,10,tmp));
- mpz_clear(n);
- mpz_clear(tmp);
- }
- void pb7(){
- mpz_t x,y;
- mpz_inits(x,y,NULL);
- mpz_set_ui(x,1);
- mpz_set_ui(y,1);
- int cnt=0;
- while(cnt< 10001){
- mpz_nextprime(x,y);
- mpz_set(y,x);
- cnt++;
- }
- printf("%s \n",mpz_get_str(NULL,10,x));
- mpz_clear(x);
- mpz_clear(y);
- }
- /*
- int isPallindrome(unsigned n){
- return (rev(n)==n) ;
- }
- */
- int isPallindrome( mpz_t n){
- mpz_t rn;
- mpz_init(rn);
- rev(rn,n);
- //printf("%s\n", mpz_get_str(NULL,10,rn));
- //printf("%d\n", mpz_cmp(rn,n));
- //printf("n = %s\n", mpz_get_str(NULL,10,n));
- if (mpz_cmp(n, rn)==0){
- return 1;
- }
- return 0;
- }
- void rev(mpz_t rop, const mpz_t op){
- mpz_t tmp, tmp2;
- mpz_inits(tmp, tmp2, NULL);
- mpz_set(tmp2, op);
- mpz_set_ui(rop, 0);
- while(mpz_get_ui(tmp2) != 0){
- mpz_mul_ui(rop, rop ,10);
- mpz_mod_ui(tmp, tmp2 ,10);
- mpz_add(rop,rop,tmp);
- mpz_fdiv_q_ui(tmp2,tmp2,10);
- }
- mpz_clears(tmp,tmp2,NULL);
- }
- /*
- mpz_t tmp, tmp2;
- mpz_inits(tmp,tmp2,NULL);
- mpz_set_ui(reverse,0);
- mpz_set(tmp2,n);
- while(mpz_get_ui(n) != 0){
- mpz_mul_ui(reverse,reverse,10);
- mpz_mod_ui(tmp,n,10);
- mpz_add(reverse,reverse,tmp);
- mpz_fdiv_q_ui(n,n, 10);
- }
- mpz_swap(n,tmp2);
- mpz_clears(tmp,tmp2,NULL);
- }
- */
- void reverse_and_add(mpz_t res, const mpz_t n){
- mpz_t tmp;
- mpz_init(tmp);
- rev(tmp,n);
- mpz_add(res,tmp,n);
- mpz_clear(tmp);
- }
- void mpz_print(const mpz_t n){
- printf("%s\n", mpz_get_str(NULL,10,n));
- }
- int isLychrel(const mpz_t i){
- int cnt=0;
- mps_t n,tmp;
- mpz_inits(n,tmp,NULL);
- mpz_set(n,i);
- while(cnt<50){
- reverse_and_add(tmp,n);
- mpz_swap(n,tmp);
- if (isPallindrome(n)){
- return 0;
- }
- cnt++;
- }
- return 1;
- }
- void pb55(){
- int cnt = 0;
- }
- int main(int argc, char **argv){
- mpz_t n,m;
- mpz_inits(n,m,NULL);
- mpz_set_ui(n,123456);
- rev(m,n);
- printf("%s",mpz_get_str(NULL,10,m));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement