Advertisement
Guest User

Untitled

a guest
Aug 13th, 2016
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include "euler.h"
  3. #include <gmp.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. #include "smmintrin.h"
  8. #include "emmintrin.h"
  9. #include <immintrin.h>
  10.  
  11.  
  12. void pb1(){
  13.     int i, sum=0;
  14.     for(i=0;i<1e3;i++){
  15.         if (i%3==0 || i%5==0){
  16.             sum+=i;
  17.         }
  18.     }
  19.    
  20.     printf("%d\n", sum);
  21. }
  22.  
  23. void pb2(){
  24.    
  25.     mpz_t a, b,r,two;
  26.     mpz_inits(a,b,r,two,NULL);
  27.  
  28.     mpz_set_ui(a,1);
  29.     mpz_set_ui(b,0);
  30.     mpz_set_ui(r,1);
  31.     mpz_set_ui(two,2);
  32.     int i=0;
  33.     while (mpz_get_ui(a)< 4000000){
  34.         mpz_fib_ui(a,i);
  35.         mpz_mod(r,a,two);
  36.         if( mpz_get_ui(r)==0){
  37.             mpz_add_ui(b,b,mpz_get_ui(a));
  38.         }
  39.         i++;
  40.     }
  41.  
  42.     printf("%s \n", mpz_get_str(NULL,10,b));
  43.     mpz_clears(a,r,b,two,NULL);
  44. }
  45.  
  46. void pb4(){
  47.     unsigned long long n=21,flag = 0;
  48.     while(flag==0){
  49.         if (isDivisible(n)==1){
  50.             flag = 1;
  51.             printf("%lld\n", n);
  52.         }
  53.         n+=2;
  54.     }
  55.  
  56.  
  57. }
  58.  
  59.  
  60. void pb9(){
  61.     int a,b,c;
  62.     for(a=1;a<1000;a++){
  63.         for(b=1;b<1000;b++){
  64.             for(c=1;c<1000;c++){
  65.                 if (a+b+c==1000 && a*a+b*b==c*c){
  66.                     printf("%d\n", a*b*c);  
  67.                     return;  
  68.                 }
  69.             }
  70.         }
  71.     }
  72. }
  73.  
  74. void pb14(){
  75.     unsigned n,i,cnt,res = 0, max_cnt=0;
  76.     for (i=1;i<1e6;i++){
  77.         n=i;
  78.         cnt=0;
  79.         while(n!=1){
  80.             n=(n&1)?3*n+1 :n/2;
  81.             cnt++;
  82.         }
  83.         if (cnt > max_cnt){
  84.             max_cnt = cnt;
  85.             res = i;
  86.         }            
  87.     }
  88.     printf("%d\n", res);
  89. }
  90.  
  91. void pb16(){
  92.     unsigned long i=0;
  93.     mpz_t n, tmp;
  94.     mpz_inits(n,tmp,NULL);
  95.     mpz_set_ui(tmp,0);
  96.     mpz_set_ui(n,0);
  97.  
  98.     mpz_ui_pow_ui(n,2,1000);
  99.     while(mpz_sgn(n)){
  100.         i+= mpz_mod_ui(tmp,n,10);
  101.         mpz_fdiv_q_ui(n,n,10);
  102.     }
  103.  
  104.     printf("%ld\n", i);
  105.     printf("%s\n", mpz_get_str(NULL,10,tmp));
  106.     mpz_clear(n);
  107.     mpz_clear(tmp);    
  108.  
  109. }
  110.  
  111. void pb7(){
  112.     mpz_t x,y;
  113.     mpz_inits(x,y,NULL);
  114.     mpz_set_ui(x,1);
  115.     mpz_set_ui(y,1);
  116.     int cnt=0;
  117.     while(cnt< 10001){
  118.         mpz_nextprime(x,y);
  119.         mpz_set(y,x);
  120.         cnt++;
  121.     }
  122.  
  123.     printf("%s \n",mpz_get_str(NULL,10,x));
  124.     mpz_clear(x);
  125.     mpz_clear(y);
  126. }
  127.  
  128. /*
  129.  
  130. int isPallindrome(unsigned  n){
  131.     return (rev(n)==n) ;
  132. }
  133. */
  134.  
  135.  
  136. int isPallindrome( mpz_t n){
  137.     mpz_t rn;
  138.     mpz_init(rn);
  139.     rev(rn,n);
  140.     //printf("%s\n", mpz_get_str(NULL,10,rn));
  141.     //printf("%d\n", mpz_cmp(rn,n));
  142.     //printf("n = %s\n", mpz_get_str(NULL,10,n));
  143.     if (mpz_cmp(n, rn)==0){
  144.         return 1;
  145.     }
  146.     return 0;
  147. }
  148.  
  149. void rev(mpz_t rop, const mpz_t op){
  150.     mpz_t tmp, tmp2;
  151.     mpz_inits(tmp, tmp2, NULL);
  152.     mpz_set(tmp2, op);
  153.  
  154.     mpz_set_ui(rop, 0);
  155.     while(mpz_get_ui(tmp2) != 0){
  156.  
  157.         mpz_mul_ui(rop, rop ,10);
  158.         mpz_mod_ui(tmp, tmp2 ,10);
  159.         mpz_add(rop,rop,tmp);
  160.         mpz_fdiv_q_ui(tmp2,tmp2,10);
  161.     }
  162.    
  163.     mpz_clears(tmp,tmp2,NULL);
  164. }
  165.  
  166. /*    
  167.     mpz_t  tmp, tmp2;
  168.     mpz_inits(tmp,tmp2,NULL);
  169.     mpz_set_ui(reverse,0);
  170.     mpz_set(tmp2,n);
  171.     while(mpz_get_ui(n) != 0){
  172.         mpz_mul_ui(reverse,reverse,10);
  173.         mpz_mod_ui(tmp,n,10);
  174.         mpz_add(reverse,reverse,tmp);
  175.         mpz_fdiv_q_ui(n,n, 10);
  176.     }
  177.  
  178.     mpz_swap(n,tmp2);
  179.     mpz_clears(tmp,tmp2,NULL);
  180. }
  181.  
  182. */
  183. void reverse_and_add(mpz_t res, const mpz_t n){
  184.     mpz_t tmp;
  185.     mpz_init(tmp);
  186.     rev(tmp,n);
  187.     mpz_add(res,tmp,n);
  188.     mpz_clear(tmp);
  189. }
  190. void mpz_print(const mpz_t n){
  191.     printf("%s\n", mpz_get_str(NULL,10,n));
  192. }
  193.  
  194. int isLychrel(const mpz_t i){
  195.     int cnt=0;
  196.     mps_t n,tmp;
  197.     mpz_inits(n,tmp,NULL);
  198.     mpz_set(n,i);
  199.     while(cnt<50){
  200.         reverse_and_add(tmp,n);
  201.         mpz_swap(n,tmp);
  202.         if (isPallindrome(n)){
  203.             return 0;
  204.         }
  205.         cnt++;
  206.     }
  207.     return 1;
  208. }
  209. void pb55(){
  210.     int cnt = 0;
  211.    
  212.  
  213. }
  214. int main(int argc, char **argv){
  215.     mpz_t n,m;
  216.     mpz_inits(n,m,NULL);
  217.     mpz_set_ui(n,123456);
  218.     rev(m,n);
  219.     printf("%s",mpz_get_str(NULL,10,m));
  220.    
  221.  
  222.     return 0;
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement